Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: ash/shell/window_watcher.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shell/window_type_launcher.cc ('k') | ash/shell/window_watcher_shelf_item_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shell/window_watcher.h" 5 #include "ash/shell/window_watcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/shelf/shelf_item_delegate_manager.h" 9 #include "ash/common/shelf/shelf_item_delegate_manager.h"
10 #include "ash/common/shelf/shelf_model.h" 10 #include "ash/common/shelf/shelf_model.h"
11 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
12 #include "ash/display/window_tree_host_manager.h" 12 #include "ash/display/window_tree_host_manager.h"
13 #include "ash/shelf/shelf.h" 13 #include "ash/shelf/shelf.h"
14 #include "ash/shelf/shelf_util.h" 14 #include "ash/shelf/shelf_util.h"
15 #include "ash/shelf/shelf_widget.h" 15 #include "ash/shelf/shelf_widget.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/shell/window_watcher_shelf_item_delegate.h" 17 #include "ash/shell/window_watcher_shelf_item_delegate.h"
18 #include "ash/wm/window_util.h" 18 #include "ash/wm/window_util.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/aura/window_event_dispatcher.h" 20 #include "ui/aura/window_event_dispatcher.h"
21 #include "ui/display/display.h" 21 #include "ui/display/display.h"
22 22
23 namespace ash { 23 namespace ash {
24 namespace shell { 24 namespace shell {
25 25
26 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { 26 class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver {
27 public: 27 public:
28 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) { 28 explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) {}
29 }
30 29
31 ~WorkspaceWindowWatcher() override {} 30 ~WorkspaceWindowWatcher() override {}
32 31
33 void OnWindowAdded(aura::Window* new_window) override { 32 void OnWindowAdded(aura::Window* new_window) override {
34 new_window->AddObserver(watcher_); 33 new_window->AddObserver(watcher_);
35 } 34 }
36 35
37 void OnWillRemoveWindow(aura::Window* window) override { 36 void OnWillRemoveWindow(aura::Window* window) override {
38 DCHECK(window->children().empty()); 37 DCHECK(window->children().empty());
39 window->RemoveObserver(watcher_); 38 window->RemoveObserver(watcher_);
(...skipping 26 matching lines...) Expand all
66 private: 65 private:
67 WindowWatcher* watcher_; 66 WindowWatcher* watcher_;
68 67
69 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); 68 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher);
70 }; 69 };
71 70
72 WindowWatcher::WindowWatcher() { 71 WindowWatcher::WindowWatcher() {
73 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this)); 72 workspace_window_watcher_.reset(new WorkspaceWindowWatcher(this));
74 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 73 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
75 for (aura::Window::Windows::iterator iter = root_windows.begin(); 74 for (aura::Window::Windows::iterator iter = root_windows.begin();
76 iter != root_windows.end(); ++ iter) { 75 iter != root_windows.end(); ++iter) {
77 workspace_window_watcher_->RootWindowAdded(*iter); 76 workspace_window_watcher_->RootWindowAdded(*iter);
78 } 77 }
79 } 78 }
80 79
81 WindowWatcher::~WindowWatcher() { 80 WindowWatcher::~WindowWatcher() {
82 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 81 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
83 for (aura::Window::Windows::iterator iter = root_windows.begin(); 82 for (aura::Window::Windows::iterator iter = root_windows.begin();
84 iter != root_windows.end(); ++ iter) { 83 iter != root_windows.end(); ++iter) {
85 workspace_window_watcher_->RootWindowRemoved(*iter); 84 workspace_window_watcher_->RootWindowRemoved(*iter);
86 } 85 }
87 } 86 }
88 87
89 aura::Window* WindowWatcher::GetWindowByID(ash::ShelfID id) { 88 aura::Window* WindowWatcher::GetWindowByID(ash::ShelfID id) {
90 IDToWindow::const_iterator i = id_to_window_.find(id); 89 IDToWindow::const_iterator i = id_to_window_.find(id);
91 return i != id_to_window_.end() ? i->second : NULL; 90 return i != id_to_window_.end() ? i->second : NULL;
92 } 91 }
93 92
94 // aura::WindowObserver overrides: 93 // aura::WindowObserver overrides:
95 void WindowWatcher::OnWindowAdded(aura::Window* new_window) { 94 void WindowWatcher::OnWindowAdded(aura::Window* new_window) {
96 if (!wm::IsWindowUserPositionable(new_window)) 95 if (!wm::IsWindowUserPositionable(new_window))
97 return; 96 return;
98 97
99 static int image_count = 0; 98 static int image_count = 0;
100 ShelfModel* model = Shell::GetInstance()->shelf_model(); 99 ShelfModel* model = Shell::GetInstance()->shelf_model();
101 ShelfItem item; 100 ShelfItem item;
102 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL 101 item.type = new_window->type() == ui::wm::WINDOW_TYPE_PANEL
103 ? ash::TYPE_APP_PANEL 102 ? ash::TYPE_APP_PANEL
104 : ash::TYPE_PLATFORM_APP; 103 : ash::TYPE_PLATFORM_APP;
105 ash::ShelfID id = model->next_id(); 104 ash::ShelfID id = model->next_id();
106 id_to_window_[id] = new_window; 105 id_to_window_[id] = new_window;
107 106
108 SkBitmap icon_bitmap; 107 SkBitmap icon_bitmap;
109 icon_bitmap.allocN32Pixels(16, 16); 108 icon_bitmap.allocN32Pixels(16, 16);
110 icon_bitmap.eraseARGB(255, 109 icon_bitmap.eraseARGB(255, image_count == 0 ? 255 : 0,
111 image_count == 0 ? 255 : 0, 110 image_count == 1 ? 255 : 0, image_count == 2 ? 255 : 0);
112 image_count == 1 ? 255 : 0,
113 image_count == 2 ? 255 : 0);
114 image_count = (image_count + 1) % 3; 111 image_count = (image_count + 1) % 3;
115 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); 112 item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f));
116 113
117 model->Add(item); 114 model->Add(item);
118 115
119 ShelfItemDelegateManager* manager = 116 ShelfItemDelegateManager* manager =
120 Shell::GetInstance()->shelf_item_delegate_manager(); 117 Shell::GetInstance()->shelf_item_delegate_manager();
121 std::unique_ptr<ShelfItemDelegate> delegate( 118 std::unique_ptr<ShelfItemDelegate> delegate(
122 new WindowWatcherShelfItemDelegate(id, this)); 119 new WindowWatcherShelfItemDelegate(id, this));
123 manager->SetShelfItemDelegate(id, std::move(delegate)); 120 manager->SetShelfItemDelegate(id, std::move(delegate));
124 SetShelfIDForWindow(id, new_window); 121 SetShelfIDForWindow(id, new_window);
125 } 122 }
126 123
127 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { 124 void WindowWatcher::OnWillRemoveWindow(aura::Window* window) {
128 for (IDToWindow::iterator i = id_to_window_.begin(); 125 for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end();
129 i != id_to_window_.end(); ++i) { 126 ++i) {
130 if (i->second == window) { 127 if (i->second == window) {
131 ShelfModel* model = Shell::GetInstance()->shelf_model(); 128 ShelfModel* model = Shell::GetInstance()->shelf_model();
132 int index = model->ItemIndexByID(i->first); 129 int index = model->ItemIndexByID(i->first);
133 DCHECK_NE(-1, index); 130 DCHECK_NE(-1, index);
134 model->RemoveItemAt(index); 131 model->RemoveItemAt(index);
135 id_to_window_.erase(i); 132 id_to_window_.erase(i);
136 break; 133 break;
137 } 134 }
138 } 135 }
139 } 136 }
140 137
141 void WindowWatcher::OnDisplayAdded(const display::Display& new_display) { 138 void WindowWatcher::OnDisplayAdded(const display::Display& new_display) {
142 aura::Window* root = Shell::GetInstance() 139 aura::Window* root = Shell::GetInstance()
143 ->window_tree_host_manager() 140 ->window_tree_host_manager()
144 ->GetRootWindowForDisplayId(new_display.id()); 141 ->GetRootWindowForDisplayId(new_display.id());
145 workspace_window_watcher_->RootWindowAdded(root); 142 workspace_window_watcher_->RootWindowAdded(root);
146 } 143 }
147 144
148 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) { 145 void WindowWatcher::OnDisplayRemoved(const display::Display& old_display) {
149 // All windows in the display has already been removed, so no need to 146 // All windows in the display has already been removed, so no need to
150 // remove observers. 147 // remove observers.
151 } 148 }
152 149
153 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) { 150 void WindowWatcher::OnDisplayMetricsChanged(const display::Display&, uint32_t) {
154 } 151 }
155 152
156 } // namespace shell 153 } // namespace shell
157 } // namespace ash 154 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell/window_type_launcher.cc ('k') | ash/shell/window_watcher_shelf_item_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698