123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- // Copyright 2017 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ash/public/cpp/shelf_types.h"
- #include "base/logging.h"
- #include "base/notreached.h"
- #include "base/strings/string_split.h"
- namespace ash {
- namespace {
- // A delimiter used to serialize the ShelfID string pair as a single string.
- constexpr char kDelimiter[] = "|";
- } // namespace
- std::ostream& operator<<(std::ostream& out, ShelfAutoHideState state) {
- switch (state) {
- case SHELF_AUTO_HIDE_SHOWN:
- return out << "SHOWN";
- case SHELF_AUTO_HIDE_HIDDEN:
- return out << "HIDDEN";
- }
- }
- std::ostream& operator<<(std::ostream& out, ShelfBackgroundType type) {
- switch (type) {
- case ShelfBackgroundType::kDefaultBg:
- return out << "DefaultBg";
- case ShelfBackgroundType::kMaximized:
- return out << "Maximized";
- case ShelfBackgroundType::kAppList:
- return out << "AppList";
- case ShelfBackgroundType::kHomeLauncher:
- return out << "HomeLauncher";
- case ShelfBackgroundType::kMaximizedWithAppList:
- return out << "MaximizedWithAppList";
- case ShelfBackgroundType::kOobe:
- return out << "Oobe";
- case ShelfBackgroundType::kLogin:
- return out << "Login";
- case ShelfBackgroundType::kLoginNonBlurredWallpaper:
- return out << "LoginNonBlurredWallpaper";
- case ShelfBackgroundType::kOverview:
- return out << "Overview";
- case ShelfBackgroundType::kInApp:
- return out << "InApp";
- }
- }
- bool IsValidShelfItemType(int64_t type) {
- switch (type) {
- case TYPE_PINNED_APP:
- case TYPE_BROWSER_SHORTCUT:
- case TYPE_APP:
- case TYPE_UNPINNED_BROWSER_SHORTCUT:
- case TYPE_DIALOG:
- case TYPE_UNDEFINED:
- return true;
- }
- return false;
- }
- bool IsPinnedShelfItemType(ShelfItemType type) {
- switch (type) {
- case TYPE_PINNED_APP:
- case TYPE_BROWSER_SHORTCUT:
- return true;
- case TYPE_APP:
- case TYPE_UNPINNED_BROWSER_SHORTCUT:
- case TYPE_DIALOG:
- case TYPE_UNDEFINED:
- return false;
- }
- NOTREACHED();
- return false;
- }
- bool SamePinState(ShelfItemType a, ShelfItemType b) {
- if (!IsPinnedShelfItemType(a) && a != TYPE_APP)
- return false;
- if (!IsPinnedShelfItemType(b) && b != TYPE_APP)
- return false;
- const bool a_unpinned = (a == TYPE_APP);
- const bool b_unpinned = (b == TYPE_APP);
- return a_unpinned == b_unpinned;
- }
- ShelfID::ShelfID(const std::string& app_id, const std::string& launch_id)
- : app_id(app_id), launch_id(launch_id) {
- DCHECK(launch_id.empty() || !app_id.empty()) << "launch ids require app ids.";
- }
- ShelfID::~ShelfID() = default;
- ShelfID::ShelfID(const ShelfID& other) = default;
- ShelfID::ShelfID(ShelfID&& other) = default;
- ShelfID& ShelfID::operator=(const ShelfID& other) = default;
- bool ShelfID::operator==(const ShelfID& other) const {
- return app_id == other.app_id && launch_id == other.launch_id;
- }
- bool ShelfID::operator!=(const ShelfID& other) const {
- return !(*this == other);
- }
- bool ShelfID::operator<(const ShelfID& other) const {
- return app_id < other.app_id ||
- (app_id == other.app_id && launch_id < other.launch_id);
- }
- bool ShelfID::IsNull() const {
- return app_id.empty() && launch_id.empty();
- }
- std::string ShelfID::Serialize() const {
- DCHECK_EQ(std::string::npos, app_id.find(kDelimiter)) << "Invalid ShelfID";
- DCHECK_EQ(std::string::npos, launch_id.find(kDelimiter)) << "Invalid ShelfID";
- return app_id + kDelimiter + launch_id;
- }
- // static
- ShelfID ShelfID::Deserialize(const std::string* string) {
- if (!string)
- return ShelfID();
- std::vector<std::string> components = base::SplitString(
- *string, kDelimiter, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
- DCHECK_EQ(2u, components.size()) << "ShelfID serialized incorrectly.";
- return ShelfID(components[0], components[1]);
- }
- std::ostream& operator<<(std::ostream& o, const ShelfID& id) {
- return o << "app_id:" << id.app_id << ", launch_id:" << id.launch_id;
- }
- } // namespace ash
|