Commit 16ae0289 authored by msw's avatar msw Committed by Commit bot

Fork a subset of ash/shelf for use in mash.

Fork Shelf View, Model, Button, TooltipManager, etc.
These provide a baseline of ash/shelf-like functionality.
(show open mash windows, support reordering, tooltips, etc.)

Restructure some ownership patterns (eg. shelf owns model).
Minimal code refactoring, removal and commenting.
(attempt to minimize diff, keep/stub some features)

TODO: Restore missing functionality/tests.

BUG=557406
TEST=mojo:mash_shell's shelf starts looking more like ash.
R=sky@chromium.org,bungeman@google.com

Review URL: https://codereview.chromium.org/1585363002

Cr-Commit-Position: refs/heads/master@{#371866}
parent 58c568b9
...@@ -6,11 +6,25 @@ import("//build/config/ui.gni") ...@@ -6,11 +6,25 @@ import("//build/config/ui.gni")
import("//mojo/public/mojo_application.gni") import("//mojo/public/mojo_application.gni")
import("//mojo/public/tools/bindings/mojom.gni") import("//mojo/public/tools/bindings/mojom.gni")
# TODO(msw): Port unit/app tests: model, view, tooltip_manager, etc.
mojo_native_application("shelf") { mojo_native_application("shelf") {
sources = [ sources = [
"main.cc", "main.cc",
"shelf_application.cc", "shelf_application.cc",
"shelf_application.h", "shelf_application.h",
"shelf_button.cc",
"shelf_button.h",
"shelf_button_host.h",
"shelf_constants.cc",
"shelf_constants.h",
"shelf_item_types.cc",
"shelf_item_types.h",
"shelf_model.cc",
"shelf_model.h",
"shelf_model_observer.h",
"shelf_tooltip_manager.cc",
"shelf_tooltip_manager.h",
"shelf_types.h",
"shelf_view.cc", "shelf_view.cc",
"shelf_view.h", "shelf_view.h",
] ]
...@@ -24,9 +38,12 @@ mojo_native_application("shelf") { ...@@ -24,9 +38,12 @@ mojo_native_application("shelf") {
"//mojo/services/tracing/public/cpp", "//mojo/services/tracing/public/cpp",
"//mojo/shell/public/cpp", "//mojo/shell/public/cpp",
"//skia", "//skia",
"//ui/accessibility",
"//ui/aura", "//ui/aura",
"//ui/resources",
"//ui/views", "//ui/views",
"//ui/views/mus:for_mojo_application", "//ui/views/mus:for_mojo_application",
"//ui/wm",
] ]
resources = [ "$root_out_dir/views_mus_resources.pak" ] resources = [ "$root_out_dir/views_mus_resources.pak" ]
......
include_rules = [
"+skia",
]
\ No newline at end of file
...@@ -27,11 +27,10 @@ void ShelfApplication::Initialize(mojo::ApplicationImpl* app) { ...@@ -27,11 +27,10 @@ void ShelfApplication::Initialize(mojo::ApplicationImpl* app) {
aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak")); aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
views::WindowManagerConnection::Create(app); views::WindowManagerConnection::Create(app);
// Construct the shelf using a container tagged for positioning by the WM.
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.delegate = new ShelfView(app);
std::map<std::string, std::vector<uint8_t>> properties; std::map<std::string, std::vector<uint8_t>> properties;
properties[mash::wm::mojom::kWindowContainer_Property] = properties[mash::wm::mojom::kWindowContainer_Property] =
mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert( mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
...@@ -41,6 +40,9 @@ void ShelfApplication::Initialize(mojo::ApplicationImpl* app) { ...@@ -41,6 +40,9 @@ void ShelfApplication::Initialize(mojo::ApplicationImpl* app) {
params.native_widget = new views::NativeWidgetMus( params.native_widget = new views::NativeWidgetMus(
widget, app->shell(), window, mus::mojom::SurfaceType::DEFAULT); widget, app->shell(), window, mus::mojom::SurfaceType::DEFAULT);
widget->Init(params); widget->Init(params);
widget->SetContentsView(new ShelfView(app));
// Call CenterWindow to mimic Widget::Init's placement with a widget delegate.
widget->CenterWindow(widget->GetContentsView()->GetPreferredSize());
widget->Show(); widget->Show();
} }
......
This diff is collapsed.
// Copyright 2013 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.
#ifndef MASH_SHELF_SHELF_BUTTON_H_
#define MASH_SHELF_SHELF_BUTTON_H_
#include "base/macros.h"
#include "mash/shelf/shelf_types.h"
#include "ui/gfx/shadow_value.h"
#include "ui/views/controls/button/custom_button.h"
#include "ui/views/controls/image_view.h"
namespace mash {
namespace shelf {
class ShelfButtonHost;
// Button used for items on the launcher, except for the AppList.
class ShelfButton : public views::CustomButton {
public:
static const char kViewClassName[];
// Used to indicate the current state of the button.
enum State {
// Nothing special. Usually represents an app shortcut item with no running
// instance.
STATE_NORMAL = 0,
// Button has mouse hovering on it.
STATE_HOVERED = 1 << 0,
// Underlying ShelfItem has a running instance.
STATE_RUNNING = 1 << 1,
// Underlying ShelfItem is active (i.e. has focus).
STATE_ACTIVE = 1 << 2,
// Underlying ShelfItem needs user's attention.
STATE_ATTENTION = 1 << 3,
STATE_FOCUSED = 1 << 4,
// Hide the status (temporarily for some animations).
STATE_HIDDEN = 1 << 5,
};
~ShelfButton() override;
// Called to create an instance of a ShelfButton.
static ShelfButton* Create(views::ButtonListener* listener,
ShelfButtonHost* host);
// Sets the image to display for this entry.
void SetImage(const gfx::ImageSkia& image);
// Retrieve the image to show proxy operations.
const gfx::ImageSkia& GetImage() const;
// |state| is or'd into the current state.
void AddState(State state);
void ClearState(State state);
int state() const { return state_; }
// Returns the bounds of the icon.
gfx::Rect GetIconBounds() const;
// Overrides to views::CustomButton:
void ShowContextMenu(const gfx::Point& p,
ui::MenuSourceType source_type) override;
// View override - needed by unit test.
void OnMouseCaptureLost() override;
protected:
ShelfButton(views::ButtonListener* listener,
ShelfButtonHost* host);
// Class that draws the icon part of a button, so it can be animated
// independently of the rest. This can be subclassed to provide a custom
// implementation, by overriding CreateIconView().
class IconView : public views::ImageView {
public:
IconView();
~IconView() override;
void set_icon_size(int icon_size) { icon_size_ = icon_size; }
int icon_size() const { return icon_size_; }
private:
// Set to non-zero to force icons to be resized to fit within a square,
// while maintaining original proportions.
int icon_size_;
DISALLOW_COPY_AND_ASSIGN(IconView);
};
// View overrides:
const char* GetClassName() const override;
bool OnMousePressed(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
void OnMouseMoved(const ui::MouseEvent& event) override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
void GetAccessibleState(ui::AXViewState* state) override;
void Layout() override;
void ChildPreferredSizeChanged(views::View* child) override;
void OnFocus() override;
void OnBlur() override;
void OnPaint(gfx::Canvas* canvas) override;
// ui::EventHandler overrides:
void OnGestureEvent(ui::GestureEvent* event) override;
// Sets the icon image with a shadow.
void SetShadowedImage(const gfx::ImageSkia& bitmap);
// Override for custom initialization.
virtual void Init();
// Override to subclass IconView.
virtual IconView* CreateIconView();
IconView* icon_view() const { return icon_view_; }
ShelfButtonHost* host() const { return host_; }
private:
class BarView;
// Updates the parts of the button to reflect the current |state_| and
// alignment. This may add or remove views, layout and paint.
void UpdateState();
// Updates the status bar (bitmap, orientation, visibility).
void UpdateBar();
ShelfButtonHost* host_;
IconView* icon_view_;
// Draws a bar underneath the image to represent the state of the application.
BarView* bar_;
// The current state of the application, multiple values of AppState are or'd
// together.
int state_;
gfx::ShadowValues icon_shadows_;
// If non-null the destuctor sets this to true. This is set while the menu is
// showing and used to detect if the menu was deleted while running.
bool* destroyed_flag_;
DISALLOW_COPY_AND_ASSIGN(ShelfButton);
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_BUTTON_H_
// Copyright 2013 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.
#ifndef MASH_SHELF_SHELF_BUTTON_HOST_H_
#define MASH_SHELF_SHELF_BUTTON_HOST_H_
#include "base/logging.h"
#include "base/strings/string16.h"
#include "mash/shelf/shelf_types.h"
namespace ui {
class LocatedEvent;
}
namespace views {
class View;
}
namespace mash {
namespace shelf {
// TODO(msw): Eliminate this abstraction and just pass pointers to ShelfView?
// The shelf buttons communicate back to the host by way of this interface.
// This interface is used to enable reordering the items on the shelf.
class ShelfButtonHost {
public:
enum Pointer {
NONE,
DRAG_AND_DROP,
MOUSE,
TOUCH,
};
virtual ShelfAlignment GetAlignment() const = 0;
virtual bool IsHorizontalAlignment() const = 0;
// Helper function for choosing values specific to the shelf alignment.
template<typename T>
T PrimaryAxisValue(T horizontal, T vertical) const {
return IsHorizontalAlignment() ? horizontal : vertical;
}
// Helper function for choosing values specific to the shelf alignment.
template<typename T>
T SelectValueForShelfAlignment(T bottom, T left, T right, T top) const {
switch (GetAlignment()) {
case SHELF_ALIGNMENT_BOTTOM: return bottom;
case SHELF_ALIGNMENT_LEFT: return left;
case SHELF_ALIGNMENT_RIGHT: return right;
case SHELF_ALIGNMENT_TOP: return top;
}
NOTREACHED();
return bottom;
}
// Invoked when a pointer device is pressed on a view.
virtual void PointerPressedOnButton(views::View* view,
Pointer pointer,
const ui::LocatedEvent& event) = 0;
// Invoked when a pointer device is dragged over a view.
virtual void PointerDraggedOnButton(views::View* view,
Pointer pointer,
const ui::LocatedEvent& event) = 0;
// Invoked either if a pointer device is released or mouse capture canceled.
virtual void PointerReleasedOnButton(views::View* view,
Pointer pointer,
bool canceled) = 0;
// Invoked when the mouse moves on the item.
virtual void MouseMovedOverButton(views::View* view) = 0;
// Invoked when the mouse enters the item.
virtual void MouseEnteredButton(views::View* view) = 0;
// Invoked when the mouse exits the item.
virtual void MouseExitedButton(views::View* view) = 0;
// Invoked to get the accessible name of the item.
virtual base::string16 GetAccessibleName(const views::View* view) = 0;
protected:
virtual ~ShelfButtonHost() {}
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_BUTTON_HOST_H_
// Copyright 2013 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 "mash/shelf/shelf_constants.h"
namespace mash {
namespace shelf {
const int kShelfBackgroundAlpha = 204;
const int kInvalidImageResourceID = -1;
const int kInvalidShelfID = 0;
const int kShelfSize = 47;
const int kShelfButtonSpacing = 10;
const int kShelfButtonSize = 44;
const int kTimeToSwitchBackgroundMs = 1000;
} // namespace shelf
} // namespace mash
// Copyright 2013 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.
#ifndef MASH_SHELF_SHELF_CONSTANTS_H_
#define MASH_SHELF_SHELF_CONSTANTS_H_
namespace mash {
namespace shelf {
// Max alpha of the shelf background.
extern const int kShelfBackgroundAlpha;
// Invalid image resource id used for ShelfItemDetails.
extern const int kInvalidImageResourceID;
extern const int kInvalidShelfID;
// Size of the shelf when visible (height when the shelf is horizontal).
extern const int kShelfSize;
// Size of the space between buttons on the shelf.
extern const int kShelfButtonSpacing;
// Size allocated for each button on the shelf.
extern const int kShelfButtonSize;
// Animation duration for switching black shelf and dock background on and off.
extern const int kTimeToSwitchBackgroundMs;
// The direction of the focus cycling.
enum CycleDirection {
CYCLE_FORWARD,
CYCLE_BACKWARD
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_CONSTANTS_H_
// Copyright 2014 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 "mash/shelf/shelf_item_types.h"
#include "mash/shelf/shelf_constants.h"
namespace mash {
namespace shelf {
ShelfItem::ShelfItem()
: type(TYPE_UNDEFINED),
id(kInvalidShelfID),
status(STATUS_CLOSED),
window_id(0) {}
ShelfItem::~ShelfItem() {}
} // namespace shelf
} // namespace mash
// Copyright 2014 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.
#ifndef MASH_SHELF_SHELF_ITEM_TYPES_H_
#define MASH_SHELF_SHELF_ITEM_TYPES_H_
#include <vector>
#include "base/strings/string16.h"
#include "ui/gfx/image/image_skia.h"
namespace mash {
namespace shelf {
typedef int ShelfID;
// The type of a shelf item.
enum ShelfItemType {
// Represents a running app panel.
TYPE_APP_PANEL,
// Represents a pinned shortcut to an app.
TYPE_APP_SHORTCUT,
// Toggles visiblity of the app list.
TYPE_APP_LIST,
// The browser shortcut button.
TYPE_BROWSER_SHORTCUT,
// Represents a platform app.
TYPE_PLATFORM_APP,
// Represents a windowed V1 browser app.
TYPE_WINDOWED_APP,
// Represents a dialog.
TYPE_DIALOG,
// TODO(msw): Integrate mojo apps with another enum type.
TYPE_MOJO_APP,
// Default value.
TYPE_UNDEFINED,
};
// Represents the status of applications in the shelf.
enum ShelfItemStatus {
// A closed shelf item, i.e. has no live instance.
STATUS_CLOSED,
// A shelf item that has live instance.
STATUS_RUNNING,
// An active shelf item that has focus.
STATUS_ACTIVE,
// A shelf item that needs user's attention.
STATUS_ATTENTION,
};
struct ShelfItem {
ShelfItem();
~ShelfItem();
ShelfItemType type;
// Image to display in the shelf.
gfx::ImageSkia image;
// Assigned by the model when the item is added.
ShelfID id;
// Running status.
ShelfItemStatus status;
// The id of an associated open window.
// TODO(msw): Support multiple open windows per button.
uint32_t window_id;
// Resource id of the image to display on the shelf.
// TODO(msw): Support window icons on the shelf.
//int image_resource_id;
// Title of the item.
base::string16 title;
};
typedef std::vector<ShelfItem> ShelfItems;
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_ITEM_TYPES_H_
// Copyright 2013 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 "mash/shelf/shelf_model.h"
#include <algorithm>
#include "mash/shelf/shelf_model_observer.h"
#include "mojo/common/common_type_converters.h"
#include "mojo/shell/public/cpp/application_impl.h"
namespace mash {
namespace shelf {
namespace {
int ShelfItemTypeToWeight(ShelfItemType type) {
switch (type) {
case TYPE_APP_LIST:
// TODO(skuhne): If the app list item becomes movable again, this need
// to be a fallthrough.
return 0;
case TYPE_BROWSER_SHORTCUT:
case TYPE_APP_SHORTCUT:
return 1;
case TYPE_WINDOWED_APP:
case TYPE_PLATFORM_APP:
case TYPE_MOJO_APP:
return 2;
case TYPE_DIALOG:
return 3;
case TYPE_APP_PANEL:
return 4;
case TYPE_UNDEFINED:
NOTREACHED() << "ShelfItemType must be set";
return -1;
}
NOTREACHED() << "Invalid type " << type;
return 1;
}
bool CompareByWeight(const ShelfItem& a, const ShelfItem& b) {
return ShelfItemTypeToWeight(a.type) < ShelfItemTypeToWeight(b.type);
}
} // namespace
ShelfModel::ShelfModel(mojo::ApplicationImpl* app)
: next_id_(1), status_(STATUS_NORMAL), binding_(this) {
app->ConnectToService("mojo:desktop_wm", &user_window_controller_);
user_window_controller_->AddUserWindowObserver(
binding_.CreateInterfacePtrAndBind());
}
ShelfModel::~ShelfModel() {
}
int ShelfModel::Add(const ShelfItem& item) {
return AddAt(static_cast<int>(items_.size()), item);
}
int ShelfModel::AddAt(int index, const ShelfItem& item) {
index = ValidateInsertionIndex(item.type, index);
items_.insert(items_.begin() + index, item);
items_[index].id = next_id_++;
FOR_EACH_OBSERVER(ShelfModelObserver, observers_, ShelfItemAdded(index));
return index;
}
void ShelfModel::RemoveItemAt(int index) {
DCHECK(index >= 0 && index < item_count());
// The app list and browser shortcut can't be removed.
DCHECK(items_[index].type != TYPE_APP_LIST &&
items_[index].type != TYPE_BROWSER_SHORTCUT);
ShelfID id = items_[index].id;
items_.erase(items_.begin() + index);
FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
ShelfItemRemoved(index, id));
}
void ShelfModel::Move(int index, int target_index) {
if (index == target_index)
return;
// TODO: this needs to enforce valid ranges.
ShelfItem item(items_[index]);
items_.erase(items_.begin() + index);
items_.insert(items_.begin() + target_index, item);
FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
ShelfItemMoved(index, target_index));
}
void ShelfModel::Set(int index, const ShelfItem& item) {
DCHECK(index >= 0 && index < item_count());
int new_index = item.type == items_[index].type ?
index : ValidateInsertionIndex(item.type, index);
ShelfItem old_item(items_[index]);
items_[index] = item;
items_[index].id = old_item.id;
FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
ShelfItemChanged(index, old_item));
// If the type changes confirm that the item is still in the right order.
if (new_index != index) {
// The move function works by removing one item and then inserting it at the
// new location. However - by removing the item first the order will change
// so that our target index needs to be corrected.
// TODO(skuhne): Moving this into the Move function breaks lots of unit
// tests. So several functions were already using this incorrectly.
// That needs to be cleaned up.
if (index < new_index)
new_index--;
Move(index, new_index);
}
}
int ShelfModel::ItemIndexByID(ShelfID id) const {
ShelfItems::const_iterator i = ItemByID(id);
return i == items_.end() ? -1 : static_cast<int>(i - items_.begin());
}
int ShelfModel::GetItemIndexForType(ShelfItemType type) {
for (size_t i = 0; i < items_.size(); ++i) {
if (items_[i].type == type)
return static_cast<int>(i);
}
return -1;
}
ShelfItems::const_iterator ShelfModel::ItemByID(int id) const {
for (ShelfItems::const_iterator i = items_.begin();
i != items_.end(); ++i) {
if (i->id == id)
return i;
}
return items_.end();
}
int ShelfModel::FirstRunningAppIndex() const {
// Since lower_bound only checks weights against each other, we do not need
// to explicitly change different running application types.
DCHECK_EQ(ShelfItemTypeToWeight(TYPE_WINDOWED_APP),
ShelfItemTypeToWeight(TYPE_PLATFORM_APP));
ShelfItem weight_dummy;
weight_dummy.type = TYPE_WINDOWED_APP;
return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
CompareByWeight) - items_.begin();
}
int ShelfModel::FirstPanelIndex() const {
ShelfItem weight_dummy;
weight_dummy.type = TYPE_APP_PANEL;
return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
CompareByWeight) - items_.begin();
}
void ShelfModel::SetStatus(Status status) {
if (status_ == status)
return;
status_ = status;
FOR_EACH_OBSERVER(ShelfModelObserver, observers_, ShelfStatusChanged());
}
void ShelfModel::AddObserver(ShelfModelObserver* observer) {
observers_.AddObserver(observer);
}
void ShelfModel::RemoveObserver(ShelfModelObserver* observer) {
observers_.RemoveObserver(observer);
}
int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const {
DCHECK(index >= 0 && index <= item_count() + 1);
// Clamp |index| to the allowed range for the type as determined by |weight|.
ShelfItem weight_dummy;
weight_dummy.type = type;
index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy,
CompareByWeight) - items_.begin(),
static_cast<ShelfItems::difference_type>(index));
index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy,
CompareByWeight) - items_.begin(),
static_cast<ShelfItems::difference_type>(index));
return index;
}
void ShelfModel::OnUserWindowObserverAdded(
mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) {
for (size_t i = 0; i < user_windows.size(); ++i)
OnUserWindowAdded(std::move(user_windows[i]));
}
void ShelfModel::OnUserWindowAdded(mash::wm::mojom::UserWindowPtr user_window) {
ShelfItem item;
item.type = TYPE_MOJO_APP;
item.status = STATUS_RUNNING;
item.window_id = user_window->window_id;
item.title = user_window->window_title.To<base::string16>();
Add(item);
}
void ShelfModel::OnUserWindowRemoved(uint32_t window_id) {
RemoveItemAt(ItemIndexByWindowID(window_id));
}
void ShelfModel::OnUserWindowTitleChanged(uint32_t window_id,
const mojo::String& window_title) {
const int index = ItemIndexByWindowID(window_id);
ShelfItem old_item(items_[index]);
items_[index].title = window_title.To<base::string16>();
FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
ShelfItemChanged(index, old_item));
}
int ShelfModel::ItemIndexByWindowID(uint32_t window_id) const {
for (size_t i = 0; i < items_.size(); ++i) {
if (items_[i].window_id == window_id)
return static_cast<int>(i);
}
return -1;
}
} // namespace shelf
} // namespace mash
// Copyright 2013 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.
#ifndef MASH_SHELF_SHELF_MODEL_H_
#define MASH_SHELF_SHELF_MODEL_H_
#include "base/macros.h"
#include "base/observer_list.h"
#include "mash/shelf/shelf_item_types.h"
#include "mash/wm/public/interfaces/user_window_controller.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace mojo {
class ApplicationImpl;
}
namespace mash {
namespace shelf {
class ShelfModelObserver;
// Model used by ShelfView.
class ShelfModel : public mash::wm::mojom::UserWindowObserver {
public:
enum Status {
STATUS_NORMAL,
// A status that indicates apps are syncing/loading.
STATUS_LOADING,
};
explicit ShelfModel(mojo::ApplicationImpl* app);
~ShelfModel() override;
// Adds a new item to the model. Returns the resulting index.
int Add(const ShelfItem& item);
// Adds the item. |index| is the requested insertion index, which may be
// modified to meet type-based ordering. Returns the actual insertion index.
int AddAt(int index, const ShelfItem& item);
// Removes the item at |index|.
void RemoveItemAt(int index);
// Moves the item at |index| to |target_index|. |target_index| is in terms
// of the model *after* the item at |index| is removed.
void Move(int index, int target_index);
// Resets the item at the specified index. The item maintains its existing
// id and type.
void Set(int index, const ShelfItem& item);
// Returns the index of the item by id.
int ItemIndexByID(ShelfID id) const;
// Returns the |index| of the item matching |type| in |items_|.
// Returns -1 if the matching item is not found.
// Note: Requires a linear search.
int GetItemIndexForType(ShelfItemType type);
// Returns the index of the first running application or the index where the
// first running application would go if there are no running (non pinned)
// applications yet.
int FirstRunningAppIndex() const;
// Returns the index of the first panel or the index where the first panel
// would go if there are no panels.
int FirstPanelIndex() const;
// Returns the id assigned to the next item added.
ShelfID next_id() const { return next_id_; }
// Returns a reserved id which will not be used by the |ShelfModel|.
ShelfID reserve_external_id() { return next_id_++; }
// Returns an iterator into items() for the item with the specified id, or
// items().end() if there is no item with the specified id.
ShelfItems::const_iterator ItemByID(ShelfID id) const;
const ShelfItems& items() const { return items_; }
int item_count() const { return static_cast<int>(items_.size()); }
void SetStatus(Status status);
Status status() const { return status_; }
void AddObserver(ShelfModelObserver* observer);
void RemoveObserver(ShelfModelObserver* observer);
// TODO(msw): Do not expose this member, used by ShelfView to FocusUserWindow.
mash::wm::mojom::UserWindowController* user_window_controller() const {
return user_window_controller_.get();
}
private:
// Overridden from mash::wm::mojom::UserWindowObserver:
void OnUserWindowObserverAdded(
mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) override;
void OnUserWindowAdded(mash::wm::mojom::UserWindowPtr user_window) override;
void OnUserWindowRemoved(uint32_t window_id) override;
void OnUserWindowTitleChanged(uint32_t window_id,
const mojo::String& window_title) override;
// Makes sure |index| is in line with the type-based order of items. If that
// is not the case, adjusts index by shifting it to the valid range and
// returns the new value.
int ValidateInsertionIndex(ShelfItemType type, int index) const;
// Return the index of the item by window id.
int ItemIndexByWindowID(uint32_t window_id) const;
// ID assigned to the next item.
ShelfID next_id_;
ShelfItems items_;
Status status_;
base::ObserverList<ShelfModelObserver> observers_;
mash::wm::mojom::UserWindowControllerPtr user_window_controller_;
mojo::Binding<mash::wm::mojom::UserWindowObserver> binding_;
DISALLOW_COPY_AND_ASSIGN(ShelfModel);
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_MODEL_H_
// Copyright 2013 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.
#ifndef MASH_SHELF_SHELF_MODEL_OBSERVER_H_
#define MASH_SHELF_SHELF_MODEL_OBSERVER_H_
#include "mash/shelf/shelf_item_types.h"
namespace mash {
namespace shelf {
struct ShelfItem;
class ShelfModelObserver {
public:
// Invoked after an item has been added to the model.
virtual void ShelfItemAdded(int index) = 0;
// Invoked after an item has been removed. |index| is the index the item was
// at.
virtual void ShelfItemRemoved(int index, ShelfID id) = 0;
// Invoked after an item has been moved. See ShelfModel::Move() for details
// of the arguments.
virtual void ShelfItemMoved(int start_index, int target_index) = 0;
// Invoked when the state of an item changes. |old_item| is the item
// before the change.
virtual void ShelfItemChanged(int index, const ShelfItem& old_item) = 0;
// Invoked when shelf status is changed.
virtual void ShelfStatusChanged() = 0;
protected:
virtual ~ShelfModelObserver() {}
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_MODEL_OBSERVER_H_
This diff is collapsed.
// Copyright 2013 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.
#ifndef MASH_SHELF_SHELF_TOOLTIP_MANAGER_H_
#define MASH_SHELF_SHELF_TOOLTIP_MANAGER_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "mash/shelf/shelf_types.h"
#include "ui/events/event_handler.h"
namespace base {
class Timer;
}
namespace views {
class BubbleDelegateView;
class View;
class Widget;
}
namespace mash {
namespace shelf {
class ShelfView;
namespace test {
class ShelfTooltipManagerTest;
class ShelfViewTest;
}
// ShelfTooltipManager manages the tooltip balloon poping up on shelf items.
class ShelfTooltipManager : public ui::EventHandler {
public:
explicit ShelfTooltipManager(ShelfView* shelf_view);
~ShelfTooltipManager() override;
// Called when the bubble is closed.
void OnBubbleClosed(views::BubbleDelegateView* view);
// Shows the tooltip after a delay. It also has the appearing animation.
void ShowDelayed(views::View* anchor, const base::string16& text);
// Shows the tooltip immediately. It omits the appearing animation.
void ShowImmediately(views::View* anchor, const base::string16& text);
// Closes the tooltip.
void Close();
// Resets the timer for the delayed showing |view_|. If the timer isn't
// running, it starts a new timer.
void ResetTimer();
// Stops the timer for the delayed showing |view_|.
void StopTimer();
// Returns true if the tooltip is currently visible.
bool IsVisible() const;
// Returns the view to which the tooltip bubble is anchored. May be NULL.
views::View* GetCurrentAnchorView() const;
// Create an instant timer for test purposes.
void CreateZeroDelayTimerForTest();
ShelfView* shelf_view() const { return shelf_view_; }
protected:
// ui::EventHandler overrides:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
void OnCancelMode(ui::CancelModeEvent* event) override;
/* TODO(msw): Restore functionality:
// ShelfLayoutManagerObserver overrides:
void WillChangeVisibilityState(ShelfVisibilityState new_state) override;
void OnAutoHideStateChanged(ShelfAutoHideState new_state) override;*/
private:
class ShelfTooltipBubble;
friend class test::ShelfViewTest;
friend class test::ShelfTooltipManagerTest;
void CancelHidingAnimation();
void CloseSoon();
void ShowInternal();
void CreateBubble(views::View* anchor, const base::string16& text);
void CreateTimer(int delay_in_ms);
ShelfTooltipBubble* view_;
views::Widget* widget_;
scoped_ptr<base::Timer> timer_;
ShelfView* shelf_view_;
base::WeakPtrFactory<ShelfTooltipManager> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManager);
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_TOOLTIP_MANAGER_H_
// Copyright (c) 2012 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.
#ifndef MASH_SHELF_SHELF_TYPES_H_
#define MASH_SHELF_SHELF_TYPES_H_
namespace mash {
namespace shelf {
enum ShelfAlignment {
SHELF_ALIGNMENT_BOTTOM,
SHELF_ALIGNMENT_LEFT,
SHELF_ALIGNMENT_RIGHT,
SHELF_ALIGNMENT_TOP,
};
enum ShelfAutoHideBehavior {
// Always auto-hide.
SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
// Never auto-hide.
SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
// Always hide.
SHELF_AUTO_HIDE_ALWAYS_HIDDEN,
};
enum ShelfVisibilityState {
// Always visible.
SHELF_VISIBLE,
// A couple of pixels are reserved at the bottom for the shelf.
SHELF_AUTO_HIDE,
// Nothing is shown. Used for fullscreen windows.
SHELF_HIDDEN,
};
enum ShelfAutoHideState {
SHELF_AUTO_HIDE_SHOWN,
SHELF_AUTO_HIDE_HIDDEN,
};
enum ShelfBackgroundType {
// The default transparent background.
SHELF_BACKGROUND_DEFAULT,
// The background when a window is overlapping.
SHELF_BACKGROUND_OVERLAP,
// The background when a window is maximized.
SHELF_BACKGROUND_MAXIMIZED,
};
} // namespace shelf
} // namespace mash
#endif // MASH_SHELF_SHELF_TYPES_H_
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment