summaryrefslogtreecommitdiffstats
path: root/mash
diff options
context:
space:
mode:
authormsw <msw@chromium.org>2016-01-14 16:16:42 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-15 00:18:02 +0000
commitccf394144a21d7aaaa7e82bc21c7ccc6269cbb65 (patch)
treeca84c7131d864bc9c0bbf3dae029305eadd368d6 /mash
parent171e59675661aafdd7056b4d563e6bccea521c02 (diff)
downloadchromium_src-ccf394144a21d7aaaa7e82bc21c7ccc6269cbb65.zip
chromium_src-ccf394144a21d7aaaa7e82bc21c7ccc6269cbb65.tar.gz
chromium_src-ccf394144a21d7aaaa7e82bc21c7ccc6269cbb65.tar.bz2
Add mash shelf support for window titles.
Add title strings (and IDs) to a UserWindow mojom struct. Get the titles from the mus::Window shared property. Add Shelf and UserWindowObserver support for title init/changes. Remove ShelfView's views_examples and task_viewer buttons. Depends on https://codereview.chromium.org/1576683002 BUG=557406 TEST=Mash shelf buttons contain associated window titles. R=sky@chromium.org Review URL: https://codereview.chromium.org/1587873002 Cr-Commit-Position: refs/heads/master@{#369625}
Diffstat (limited to 'mash')
-rw-r--r--mash/shelf/shelf_view.cc77
-rw-r--r--mash/shelf/shelf_view.h11
-rw-r--r--mash/wm/public/interfaces/user_window_controller.mojom10
-rw-r--r--mash/wm/user_window_controller_impl.cc73
-rw-r--r--mash/wm/user_window_controller_impl.h15
5 files changed, 130 insertions, 56 deletions
diff --git a/mash/shelf/shelf_view.cc b/mash/shelf/shelf_view.cc
index 6af2a5a..c477aac 100644
--- a/mash/shelf/shelf_view.cc
+++ b/mash/shelf/shelf_view.cc
@@ -6,6 +6,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "mojo/common/common_type_converters.h"
#include "mojo/shell/public/cpp/application_impl.h"
#include "ui/gfx/canvas.h"
#include "ui/views/controls/button/label_button.h"
@@ -14,12 +15,7 @@
namespace mash {
namespace shelf {
-enum ShelfButtonID {
- SHELF_BUTTON_VIEWS_EXAMPLES,
- SHELF_BUTTON_TASK_VIEWER,
-};
-
-ShelfView::ShelfView(mojo::ApplicationImpl* app) : app_(app), binding_(this) {
+ShelfView::ShelfView(mojo::ApplicationImpl* app) : binding_(this) {
app->ConnectToService("mojo:desktop_wm", &user_window_controller_);
mash::wm::mojom::UserWindowObserverPtr observer;
@@ -30,20 +26,17 @@ ShelfView::ShelfView(mojo::ApplicationImpl* app) : app_(app), binding_(this) {
SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
-
- views::LabelButton* views_examples =
- new views::LabelButton(this, base::ASCIIToUTF16("Views Examples"));
- views_examples->set_tag(SHELF_BUTTON_VIEWS_EXAMPLES);
- AddChildView(views_examples);
-
- views::LabelButton* task_viewer =
- new views::LabelButton(this, base::ASCIIToUTF16("Task Viewer"));
- task_viewer->set_tag(SHELF_BUTTON_TASK_VIEWER);
- AddChildView(task_viewer);
}
ShelfView::~ShelfView() {}
+size_t ShelfView::GetButtonIndexById(uint32_t window_id) const {
+ for (size_t i = 0; i < open_window_buttons_.size(); ++i)
+ if (static_cast<uint32_t>(open_window_buttons_[i]->tag()) == window_id)
+ return i;
+ return open_window_buttons_.size();
+}
+
void ShelfView::OnPaint(gfx::Canvas* canvas) {
canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
views::View::OnPaint(canvas);
@@ -58,24 +51,19 @@ views::View* ShelfView::GetContentsView() {
}
void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) {
- if (sender->tag() == SHELF_BUTTON_VIEWS_EXAMPLES)
- app_->ConnectToApplication("mojo:views_examples");
- else if (sender->tag() == SHELF_BUTTON_TASK_VIEWER)
- app_->ConnectToApplication("mojo:task_viewer");
- else
- user_window_controller_->FocusUserWindow(sender->tag());
+ user_window_controller_->FocusUserWindow(sender->tag());
}
-void ShelfView::OnUserWindowObserverAdded(mojo::Array<uint32_t> window_ids) {
- for (size_t i = 0; i < window_ids.size(); ++i)
- OnUserWindowAdded(window_ids[i]);
+void ShelfView::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 ShelfView::OnUserWindowAdded(uint32_t window_id) {
- // TODO(msw): Get the actual window title and icon.
+void ShelfView::OnUserWindowAdded(mash::wm::mojom::UserWindowPtr user_window) {
views::LabelButton* open_window_button = new views::LabelButton(
- this, base::ASCIIToUTF16(base::StringPrintf("Window %d", window_id)));
- open_window_button->set_tag(window_id);
+ this, user_window->window_title.To<base::string16>());
+ open_window_button->set_tag(user_window->window_id);
open_window_buttons_.push_back(open_window_button);
AddChildView(open_window_button);
Layout();
@@ -83,15 +71,28 @@ void ShelfView::OnUserWindowAdded(uint32_t window_id) {
}
void ShelfView::OnUserWindowRemoved(uint32_t window_id) {
- for (size_t i = 0; i < open_window_buttons_.size(); ++i) {
- if (static_cast<uint32_t>(open_window_buttons_[i]->tag()) == window_id) {
- views::LabelButton* button = open_window_buttons_[i];
- open_window_buttons_.erase(open_window_buttons_.begin() + i);
- RemoveChildView(button);
- delete button;
- return;
- }
- }
+ const size_t index = GetButtonIndexById(window_id);
+ if (index >= open_window_buttons_.size())
+ return;
+
+ views::LabelButton* button = open_window_buttons_[index];
+ open_window_buttons_.erase(open_window_buttons_.begin() + index);
+ RemoveChildView(button);
+ delete button;
+ Layout();
+ SchedulePaint();
+}
+
+void ShelfView::OnUserWindowTitleChanged(uint32_t window_id,
+ const mojo::String& window_title) {
+ const size_t index = GetButtonIndexById(window_id);
+ if (index >= open_window_buttons_.size())
+ return;
+
+ open_window_buttons_[index]->SetText(window_title.To<base::string16>());
+ open_window_buttons_[index]->SetMinSize(gfx::Size());
+ Layout();
+ SchedulePaint();
}
} // namespace shelf
diff --git a/mash/shelf/shelf_view.h b/mash/shelf/shelf_view.h
index f631dbd..dbe7ac02 100644
--- a/mash/shelf/shelf_view.h
+++ b/mash/shelf/shelf_view.h
@@ -33,6 +33,9 @@ class ShelfView : public views::WidgetDelegateView,
~ShelfView() override;
private:
+ // Return the index in |open_window_buttons_| corresponding to |window_id|.
+ size_t GetButtonIndexById(uint32_t window_id) const;
+
// Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override;
gfx::Size GetPreferredSize() const override;
@@ -44,11 +47,13 @@ class ShelfView : public views::WidgetDelegateView,
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overridden from mash::wm::mojom::UserWindowObserver:
- void OnUserWindowObserverAdded(mojo::Array<uint32_t> window_ids) override;
- void OnUserWindowAdded(uint32_t window_id) override;
+ 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;
- mojo::ApplicationImpl* app_;
std::vector<views::LabelButton*> open_window_buttons_;
mash::wm::mojom::UserWindowControllerPtr user_window_controller_;
mojo::Binding<mash::wm::mojom::UserWindowObserver> binding_;
diff --git a/mash/wm/public/interfaces/user_window_controller.mojom b/mash/wm/public/interfaces/user_window_controller.mojom
index 9ec33ec..6753ceb 100644
--- a/mash/wm/public/interfaces/user_window_controller.mojom
+++ b/mash/wm/public/interfaces/user_window_controller.mojom
@@ -4,14 +4,20 @@
module mash.wm.mojom;
+struct UserWindow {
+ uint32 window_id;
+ string window_title;
+};
+
// An observer of user windows within mojom::CONTAINER_USER_WINDOWS.
// TODO(msw): Observe focus changes, title/icon changes, etc.
interface UserWindowObserver {
// Called when the observer is first added to supply the initial state.
- OnUserWindowObserverAdded(array<uint32> window_ids);
+ OnUserWindowObserverAdded(array<UserWindow> user_windows);
- OnUserWindowAdded(uint32 window_id);
+ OnUserWindowAdded(UserWindow user_window);
OnUserWindowRemoved(uint32 window_id);
+ OnUserWindowTitleChanged(uint32 window_id, string window_title);
};
// An interface allowing system UIs to manage the set of user windows.
diff --git a/mash/wm/user_window_controller_impl.cc b/mash/wm/user_window_controller_impl.cc
index d4181fb..8e29814 100644
--- a/mash/wm/user_window_controller_impl.cc
+++ b/mash/wm/user_window_controller_impl.cc
@@ -4,18 +4,69 @@
#include "mash/wm/user_window_controller_impl.h"
+#include "components/mus/public/cpp/property_type_converters.h"
#include "components/mus/public/cpp/window.h"
+#include "components/mus/public/cpp/window_property.h"
#include "mash/wm/public/interfaces/container.mojom.h"
#include "mash/wm/window_manager_application.h"
+#include "mojo/common/common_type_converters.h"
namespace mash {
namespace wm {
+namespace {
+
+mojo::String GetWindowTitle(mus::Window* window) {
+ if (window->HasSharedProperty(
+ mus::mojom::WindowManager::kWindowTitle_Property)) {
+ return mojo::String::From(window->GetSharedProperty<base::string16>(
+ mus::mojom::WindowManager::kWindowTitle_Property));
+ }
+ return mojo::String(std::string());
+}
+
+mojom::UserWindowPtr GetUserWindow(mus::Window* window) {
+ mojom::UserWindowPtr user_window(mojom::UserWindow::New());
+ user_window->window_id = window->id();
+ user_window->window_title = GetWindowTitle(window);
+ return user_window;
+}
+
+} // namespace
+
+// Observes title changes on user windows. UserWindowControllerImpl uses this
+// separate observer to avoid observing duplicate tree change notifications.
+class WindowTitleObserver : public mus::WindowObserver {
+ public:
+ explicit WindowTitleObserver(UserWindowControllerImpl* controller)
+ : controller_(controller) {}
+ ~WindowTitleObserver() override {}
+
+ private:
+ // mus::WindowObserver:
+ void OnWindowSharedPropertyChanged(
+ mus::Window* window,
+ const std::string& name,
+ const std::vector<uint8_t>* old_data,
+ const std::vector<uint8_t>* new_data) override {
+ if (controller_->user_window_observer() &&
+ name == mus::mojom::WindowManager::kWindowTitle_Property) {
+ controller_->user_window_observer()->OnUserWindowTitleChanged(
+ window->id(), GetWindowTitle(window));
+ }
+ }
+
+ UserWindowControllerImpl* controller_;
+ DISALLOW_COPY_AND_ASSIGN(WindowTitleObserver);
+};
UserWindowControllerImpl::UserWindowControllerImpl() : state_(nullptr) {}
UserWindowControllerImpl::~UserWindowControllerImpl() {
- if (state_)
+ if (state_) {
GetUserWindowContainer()->RemoveObserver(this);
+ for (auto iter : GetUserWindowContainer()->children())
+ iter->RemoveObserver(window_title_observer_.get());
+ }
}
void UserWindowControllerImpl::Initialize(WindowManagerApplication* state) {
@@ -23,6 +74,9 @@ void UserWindowControllerImpl::Initialize(WindowManagerApplication* state) {
DCHECK(!state_);
state_ = state;
GetUserWindowContainer()->AddObserver(this);
+ window_title_observer_.reset(new WindowTitleObserver(this));
+ for (auto iter : GetUserWindowContainer()->children())
+ iter->AddObserver(window_title_observer_.get());
}
mus::Window* UserWindowControllerImpl::GetUserWindowContainer() const {
@@ -33,23 +87,26 @@ void UserWindowControllerImpl::OnTreeChanging(const TreeChangeParams& params) {
DCHECK(state_);
if (user_window_observer_) {
mus::Window* user_window_container = GetUserWindowContainer();
- if (params.new_parent == user_window_container)
- user_window_observer_->OnUserWindowAdded(params.target->id());
- else if (params.old_parent == user_window_container)
+ if (params.new_parent == user_window_container) {
+ params.target->AddObserver(window_title_observer_.get());
+ user_window_observer_->OnUserWindowAdded(GetUserWindow(params.target));
+ } else if (params.old_parent == user_window_container) {
+ params.target->RemoveObserver(window_title_observer_.get());
user_window_observer_->OnUserWindowRemoved(params.target->id());
+ }
}
}
void UserWindowControllerImpl::AddUserWindowObserver(
- mash::wm::mojom::UserWindowObserverPtr observer) {
+ mojom::UserWindowObserverPtr observer) {
// TODO(msw): Support multiple observers.
user_window_observer_ = std::move(observer);
const mus::Window::Children& windows = GetUserWindowContainer()->children();
- mojo::Array<uint32_t> user_windows =
- mojo::Array<uint32_t>::New(windows.size());
+ mojo::Array<mojom::UserWindowPtr> user_windows =
+ mojo::Array<mojom::UserWindowPtr>::New(windows.size());
for (size_t i = 0; i < windows.size(); ++i)
- user_windows[i] = windows[i]->id();
+ user_windows[i] = GetUserWindow(windows[i]);
user_window_observer_->OnUserWindowObserverAdded(std::move(user_windows));
}
diff --git a/mash/wm/user_window_controller_impl.h b/mash/wm/user_window_controller_impl.h
index 1737b61..d51caa7 100644
--- a/mash/wm/user_window_controller_impl.h
+++ b/mash/wm/user_window_controller_impl.h
@@ -16,13 +16,18 @@ namespace mash {
namespace wm {
class WindowManagerApplication;
+class WindowTitleObserver;
-class UserWindowControllerImpl : public mash::wm::mojom::UserWindowController,
+class UserWindowControllerImpl : public mojom::UserWindowController,
public mus::WindowObserver {
public:
UserWindowControllerImpl();
~UserWindowControllerImpl() override;
+ mojom::UserWindowObserver* user_window_observer() const {
+ return user_window_observer_.get();
+ }
+
void Initialize(WindowManagerApplication* state);
private:
@@ -32,13 +37,13 @@ class UserWindowControllerImpl : public mash::wm::mojom::UserWindowController,
// mus::WindowObserver:
void OnTreeChanging(const TreeChangeParams& params) override;
- // mash::wm::mojom::UserWindowController:
- void AddUserWindowObserver(
- mash::wm::mojom::UserWindowObserverPtr observer) override;
+ // mojom::UserWindowController:
+ void AddUserWindowObserver(mojom::UserWindowObserverPtr observer) override;
void FocusUserWindow(uint32_t window_id) override;
WindowManagerApplication* state_;
- mash::wm::mojom::UserWindowObserverPtr user_window_observer_;
+ mojom::UserWindowObserverPtr user_window_observer_;
+ scoped_ptr<WindowTitleObserver> window_title_observer_;
DISALLOW_COPY_AND_ASSIGN(UserWindowControllerImpl);
};