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

Side by Side Diff: ash/shelf/shelf_window_watcher.cc

Issue 2927693002: mash: Limit ShelfWindowWatcher to panels and dialogs. (Closed)
Patch Set: Fix panel behavior, unit tests, etc. Created 3 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/shelf/shelf_window_watcher.h" 5 #include "ash/shelf/shelf_window_watcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/public/cpp/config.h" 10 #include "ash/public/cpp/config.h"
11 #include "ash/public/cpp/shelf_model.h" 11 #include "ash/public/cpp/shelf_model.h"
12 #include "ash/public/cpp/shell_window_ids.h" 12 #include "ash/public/cpp/shell_window_ids.h"
13 #include "ash/public/cpp/window_properties.h" 13 #include "ash/public/cpp/window_properties.h"
14 #include "ash/shelf/shelf_constants.h" 14 #include "ash/shelf/shelf_constants.h"
15 #include "ash/shelf/shelf_window_watcher_item_delegate.h" 15 #include "ash/shelf/shelf_window_watcher_item_delegate.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/shell_port.h" 17 #include "ash/shell_port.h"
18 #include "ash/wm/window_state.h" 18 #include "ash/wm/window_state.h"
19 #include "ash/wm/window_util.h" 19 #include "ash/wm/window_util.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "ui/aura/client/aura_constants.h" 21 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/display/display.h" 24 #include "ui/display/display.h"
25 #include "ui/display/screen.h" 25 #include "ui/display/screen.h"
26 #include "ui/resources/grit/ui_resources.h" 26 #include "ui/resources/grit/ui_resources.h"
27 #include "ui/wm/core/transient_window_controller.h"
28 #include "ui/wm/public/activation_client.h" 27 #include "ui/wm/public/activation_client.h"
29 28
30 namespace ash { 29 namespace ash {
31 namespace { 30 namespace {
32 31
33 // Returns the window's shelf item type property value. 32 // Returns the window's shelf item type property value.
34 // Mash provides an initial default shelf item type for untyped windows. 33 // Mash returns the dialog type for normal windows without shelf item types.
35 // TODO(msw): Extend this Mash behavior to all Ash configs. 34 // TODO(msw): Extend this Mash behavior to all Ash configs.
36 ShelfItemType GetShelfItemType(aura::Window* window) { 35 ShelfItemType GetShelfItemType(aura::Window* window) {
37 if (Shell::GetAshConfig() == Config::MASH && 36 if (Shell::GetAshConfig() == Config::MASH &&
38 window->GetProperty(kShelfItemTypeKey) == TYPE_UNDEFINED && 37 window->GetProperty(kShelfItemTypeKey) == TYPE_UNDEFINED &&
38 window->type() == aura::client::WINDOW_TYPE_NORMAL &&
39 !wm::GetWindowState(window)->ignored_by_shelf()) { 39 !wm::GetWindowState(window)->ignored_by_shelf()) {
40 return TYPE_DIALOG; 40 return TYPE_DIALOG;
41 } 41 }
42 return static_cast<ShelfItemType>(window->GetProperty(kShelfItemTypeKey)); 42 return static_cast<ShelfItemType>(window->GetProperty(kShelfItemTypeKey));
43 } 43 }
44 44
45 // Returns the window's shelf id property value, or provides a default value. 45 // Returns the window's shelf id property value, or provides a default value.
46 // Mash provides an initial default shelf id for unidentified windows. 46 // Mash sets and returns an initial default shelf id for unidentified windows.
47 // TODO(msw): Extend this Mash behavior to all Ash configs. 47 // TODO(msw): Extend this Mash behavior to all Ash configs.
48 ShelfID GetShelfID(aura::Window* window) { 48 ShelfID GetShelfID(aura::Window* window) {
49 if (Shell::GetAshConfig() == Config::MASH && 49 if (Shell::GetAshConfig() == Config::MASH &&
50 !window->GetProperty(kShelfIDKey) && 50 !window->GetProperty(kShelfIDKey) &&
51 !wm::GetWindowState(window)->ignored_by_shelf()) { 51 !wm::GetWindowState(window)->ignored_by_shelf()) {
52 static int id = 0; 52 static int id = 0;
53 const ash::ShelfID shelf_id("ShelfWindowWatcher" + std::to_string(id++)); 53 const ash::ShelfID shelf_id("ShelfWindowWatcher" + std::to_string(id++));
54 window->SetProperty(kShelfIDKey, new std::string(shelf_id.Serialize())); 54 window->SetProperty(kShelfIDKey, new std::string(shelf_id.Serialize()));
55 return shelf_id; 55 return shelf_id;
56 } 56 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 void ShelfWindowWatcher::OnUserWindowDestroying(aura::Window* window) { 219 void ShelfWindowWatcher::OnUserWindowDestroying(aura::Window* window) {
220 if (observed_user_windows_.IsObserving(window)) 220 if (observed_user_windows_.IsObserving(window))
221 observed_user_windows_.Remove(window); 221 observed_user_windows_.Remove(window);
222 222
223 if (user_windows_with_items_.count(window) > 0) 223 if (user_windows_with_items_.count(window) > 0)
224 RemoveShelfItem(window); 224 RemoveShelfItem(window);
225 DCHECK_EQ(0u, user_windows_with_items_.count(window)); 225 DCHECK_EQ(0u, user_windows_with_items_.count(window));
226 } 226 }
227 227
228 void ShelfWindowWatcher::OnUserWindowPropertyChanged(aura::Window* window) { 228 void ShelfWindowWatcher::OnUserWindowPropertyChanged(aura::Window* window) {
229 if (GetShelfItemType(window) == TYPE_UNDEFINED || 229 // ShelfWindowWatcher only handles panels and dialogs for now, all other shelf
230 GetShelfID(window).IsNull() || 230 // item types are handled by ChromeLauncherController.
231 ::wm::TransientWindowController::Get()->GetTransientParent(window)) { 231 const ShelfItemType item_type = GetShelfItemType(window);
232 if ((item_type != TYPE_APP_PANEL && item_type != TYPE_DIALOG) ||
233 GetShelfID(window).IsNull()) {
232 // Remove |window|'s ShelfItem if it was added by ShelfWindowWatcher. 234 // Remove |window|'s ShelfItem if it was added by ShelfWindowWatcher.
233 if (user_windows_with_items_.count(window) > 0) 235 if (user_windows_with_items_.count(window) > 0)
234 RemoveShelfItem(window); 236 RemoveShelfItem(window);
235 return; 237 return;
236 } 238 }
237 239
238 // Update an existing ShelfWindowWatcher item when a window property changes. 240 // Update an existing ShelfWindowWatcher item when a window property changes.
239 int index = model_->ItemIndexByID(GetShelfID(window)); 241 int index = model_->ItemIndexByID(GetShelfID(window));
240 if (index > 0 && user_windows_with_items_.count(window) > 0) { 242 if (index > 0 && user_windows_with_items_.count(window) > 0) {
241 ShelfItem item = model_->items()[index]; 243 ShelfItem item = model_->items()[index];
242 UpdateShelfItemForWindow(&item, window); 244 UpdateShelfItemForWindow(&item, window);
243 model_->Set(index, item); 245 model_->Set(index, item);
244 return; 246 return;
245 } 247 }
246 248
247 // Create a new ShelfWindowWatcher item for |window|. 249 // Create a new item for |window|, if it is visible or a [minimized] panel.
sky 2017/06/07 23:50:22 Is the assumption that !visible=minimized for pane
msw 2017/06/08 00:00:11 Minimized panel windows are not visible; so it's s
248 if (index < 0) 250 if (index < 0 && (window->IsVisible() || item_type == TYPE_APP_PANEL))
249 AddShelfItem(window); 251 AddShelfItem(window);
250 } 252 }
251 253
252 void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason, 254 void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason,
253 aura::Window* gained_active, 255 aura::Window* gained_active,
254 aura::Window* lost_active) { 256 aura::Window* lost_active) {
255 if (gained_active && user_windows_with_items_.count(gained_active) > 0) 257 if (gained_active && user_windows_with_items_.count(gained_active) > 0)
256 OnUserWindowPropertyChanged(gained_active); 258 OnUserWindowPropertyChanged(gained_active);
257 if (lost_active && user_windows_with_items_.count(lost_active) > 0) 259 if (lost_active && user_windows_with_items_.count(lost_active) > 0)
258 OnUserWindowPropertyChanged(lost_active); 260 OnUserWindowPropertyChanged(lost_active);
(...skipping 21 matching lines...) Expand all
280 } 282 }
281 } 283 }
282 284
283 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) { 285 void ShelfWindowWatcher::OnDisplayRemoved(const display::Display& old_display) {
284 } 286 }
285 287
286 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, 288 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&,
287 uint32_t) {} 289 uint32_t) {}
288 290
289 } // namespace ash 291 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698