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

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

Issue 2209803004: mash: Move ShelfWindowTargeter out of shelf_widget.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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/shelf/shelf_widget.h ('k') | ash/shelf/shelf_window_targeter.h » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/aura/wm_shelf_aura.h" 7 #include "ash/aura/wm_shelf_aura.h"
8 #include "ash/aura/wm_window_aura.h" 8 #include "ash/aura/wm_window_aura.h"
9 #include "ash/common/focus_cycler.h" 9 #include "ash/common/focus_cycler.h"
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/common/session/session_state_delegate.h" 11 #include "ash/common/session/session_state_delegate.h"
12 #include "ash/common/shelf/shelf_background_animator_observer.h" 12 #include "ash/common/shelf/shelf_background_animator_observer.h"
13 #include "ash/common/shelf/shelf_constants.h" 13 #include "ash/common/shelf/shelf_constants.h"
14 #include "ash/common/shelf/shelf_delegate.h" 14 #include "ash/common/shelf/shelf_delegate.h"
15 #include "ash/common/shelf/wm_shelf.h" 15 #include "ash/common/shelf/wm_shelf.h"
16 #include "ash/common/shelf/wm_shelf_util.h" 16 #include "ash/common/shelf/wm_shelf_util.h"
17 #include "ash/common/system/status_area_widget.h" 17 #include "ash/common/system/status_area_widget.h"
18 #include "ash/common/system/tray/system_tray_delegate.h" 18 #include "ash/common/system/tray/system_tray_delegate.h"
19 #include "ash/common/wm_root_window_controller.h" 19 #include "ash/common/wm_root_window_controller.h"
20 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
21 #include "ash/shelf/dimmer_view.h" 21 #include "ash/shelf/dimmer_view.h"
22 #include "ash/shelf/shelf.h" 22 #include "ash/shelf/shelf.h"
23 #include "ash/shelf/shelf_layout_manager.h" 23 #include "ash/shelf/shelf_layout_manager.h"
24 #include "ash/shelf/shelf_window_targeter.h"
24 #include "ash/shell.h" 25 #include "ash/shell.h"
25 #include "ash/wm/status_area_layout_manager.h" 26 #include "ash/wm/status_area_layout_manager.h"
26 #include "ash/wm/workspace_controller.h" 27 #include "ash/wm/workspace_controller.h"
27 #include "base/memory/ptr_util.h" 28 #include "base/memory/ptr_util.h"
28 #include "grit/ash_resources.h" 29 #include "grit/ash_resources.h"
29 #include "ui/aura/window.h" 30 #include "ui/aura/window.h"
30 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/compositor/layer.h" 32 #include "ui/compositor/layer.h"
32 #include "ui/compositor/scoped_layer_animation_settings.h" 33 #include "ui/compositor/scoped_layer_animation_settings.h"
33 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
34 #include "ui/gfx/image/image.h" 35 #include "ui/gfx/image/image.h"
35 #include "ui/gfx/image/image_skia_operations.h" 36 #include "ui/gfx/image/image_skia_operations.h"
36 #include "ui/gfx/skbitmap_operations.h" 37 #include "ui/gfx/skbitmap_operations.h"
37 #include "ui/views/accessible_pane_view.h" 38 #include "ui/views/accessible_pane_view.h"
38 #include "ui/views/layout/fill_layout.h" 39 #include "ui/views/layout/fill_layout.h"
39 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
40 #include "ui/views/widget/widget_delegate.h" 41 #include "ui/views/widget/widget_delegate.h"
41 #include "ui/wm/core/easy_resize_window_targeter.h"
42 42
43 namespace ash { 43 namespace ash {
44 44
45 namespace { 45 namespace {
46 46
47 // Size of black border at bottom (or side) of shelf. 47 // Size of black border at bottom (or side) of shelf.
48 const int kNumBlackPixels = 3; 48 const int kNumBlackPixels = 3;
49 49
50 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the
51 // window-edge slightly overlaps with the shelf edge. The targeter also makes it
52 // easier to drag the shelf out with touch while it is hidden.
53 class ShelfWindowTargeter : public ::wm::EasyResizeWindowTargeter,
54 public ShelfLayoutManagerObserver {
55 public:
56 ShelfWindowTargeter(aura::Window* container, ShelfLayoutManager* shelf)
57 : ::wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()),
58 shelf_(shelf) {
59 WillChangeVisibilityState(shelf_->visibility_state());
60 shelf_->AddObserver(this);
61 }
62
63 ~ShelfWindowTargeter() override {
64 // |shelf_| may have been destroyed by this time.
65 if (shelf_)
66 shelf_->RemoveObserver(this);
67 }
68
69 private:
70 gfx::Insets GetInsetsForAlignment(int distance, ShelfAlignment alignment) {
71 if (alignment == SHELF_ALIGNMENT_LEFT)
72 return gfx::Insets(0, 0, 0, distance);
73 if (alignment == SHELF_ALIGNMENT_RIGHT)
74 return gfx::Insets(0, distance, 0, 0);
75 return gfx::Insets(distance, 0, 0, 0);
76 }
77
78 // ShelfLayoutManagerObserver:
79 void WillDeleteShelfLayoutManager() override {
80 shelf_->RemoveObserver(this);
81 shelf_ = nullptr;
82 }
83
84 void WillChangeVisibilityState(ShelfVisibilityState new_state) override {
85 gfx::Insets mouse_insets;
86 gfx::Insets touch_insets;
87 if (new_state == SHELF_VISIBLE) {
88 // Let clicks at the very top of the shelf through so windows can be
89 // resized with the bottom-right corner and bottom edge.
90 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset,
91 shelf_->GetAlignment());
92 } else if (new_state == SHELF_AUTO_HIDE) {
93 // Extend the touch hit target out a bit to allow users to drag shelf out
94 // while hidden.
95 touch_insets = GetInsetsForAlignment(-kWorkspaceAreaAutoHideInset,
96 shelf_->GetAlignment());
97 }
98
99 set_mouse_extend(mouse_insets);
100 set_touch_extend(touch_insets);
101 }
102
103 ShelfLayoutManager* shelf_;
104
105 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter);
106 };
107
108 } // namespace 50 } // namespace
109 51
110 // The contents view of the Shelf. This view contains ShelfView and 52 // The contents view of the Shelf. This view contains ShelfView and
111 // sizes it to the width of the shelf minus the size of the status area. 53 // sizes it to the width of the shelf minus the size of the status area.
112 class ShelfWidget::DelegateView : public views::WidgetDelegate, 54 class ShelfWidget::DelegateView : public views::WidgetDelegate,
113 public views::AccessiblePaneView, 55 public views::AccessiblePaneView,
114 public ShelfBackgroundAnimatorObserver { 56 public ShelfBackgroundAnimatorObserver {
115 public: 57 public:
116 explicit DelegateView(ShelfWidget* shelf); 58 explicit DelegateView(ShelfWidget* shelf);
117 ~DelegateView() override; 59 ~DelegateView() override;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { 272 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) {
331 const float kMaxAlpha = 255.0f; 273 const float kMaxAlpha = 255.0f;
332 opaque_background_.SetOpacity(alpha / kMaxAlpha); 274 opaque_background_.SetOpacity(alpha / kMaxAlpha);
333 } 275 }
334 276
335 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { 277 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) {
336 asset_background_alpha_ = alpha; 278 asset_background_alpha_ = alpha;
337 SchedulePaint(); 279 SchedulePaint();
338 } 280 }
339 281
340 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, 282 ShelfWidget::ShelfWidget(WmWindow* shelf_container,
341 WmWindow* wm_status_container, 283 WmWindow* status_container,
342 WmShelfAura* wm_shelf_aura, 284 WmShelfAura* wm_shelf_aura,
343 WorkspaceController* workspace_controller) 285 WorkspaceController* workspace_controller)
344 : wm_shelf_aura_(wm_shelf_aura), 286 : wm_shelf_aura_(wm_shelf_aura),
345 delegate_view_(new DelegateView(this)), 287 delegate_view_(new DelegateView(this)),
346 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_), 288 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_),
347 activating_as_fallback_(false) { 289 activating_as_fallback_(false) {
348 background_animator_.AddObserver(this); 290 background_animator_.AddObserver(this);
349 background_animator_.AddObserver(delegate_view_); 291 background_animator_.AddObserver(delegate_view_);
350 292
351 views::Widget::InitParams params( 293 views::Widget::InitParams params(
352 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 294 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
353 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 295 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
354 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 296 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
355 params.delegate = delegate_view_; 297 params.delegate = delegate_view_;
356 wm_shelf_container->GetRootWindowController() 298 shelf_container->GetRootWindowController()
357 ->ConfigureWidgetInitParamsForContainer( 299 ->ConfigureWidgetInitParamsForContainer(
358 this, wm_shelf_container->GetShellWindowId(), &params); 300 this, shelf_container->GetShellWindowId(), &params);
359 Init(params); 301 Init(params);
360 302
361 // The shelf should not take focus when initially shown. 303 // The shelf should not take focus when initially shown.
362 set_focus_on_creation(false); 304 set_focus_on_creation(false);
363 SetContentsView(delegate_view_); 305 SetContentsView(delegate_view_);
364 delegate_view_->SetParentLayer(GetLayer()); 306 delegate_view_->SetParentLayer(GetLayer());
365 307
366 shelf_layout_manager_ = new ShelfLayoutManager(this); 308 shelf_layout_manager_ = new ShelfLayoutManager(this);
367 shelf_layout_manager_->AddObserver(this); 309 shelf_layout_manager_->AddObserver(this);
368 wm_shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_)); 310 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_));
369 shelf_layout_manager_->set_workspace_controller(workspace_controller); 311 shelf_layout_manager_->set_workspace_controller(workspace_controller);
370 workspace_controller->SetShelf(shelf_layout_manager_); 312 workspace_controller->SetShelf(shelf_layout_manager_);
371 background_animator_.PaintBackground( 313 background_animator_.PaintBackground(
372 shelf_layout_manager_->GetShelfBackgroundType(), 314 shelf_layout_manager_->GetShelfBackgroundType(),
373 BACKGROUND_CHANGE_IMMEDIATE); 315 BACKGROUND_CHANGE_IMMEDIATE);
374 wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_); 316 wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_);
375 317
376 // TODO(jamescook): Move ownership to RootWindowController. 318 // TODO(jamescook): Move ownership to RootWindowController.
377 status_area_widget_ = 319 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_aura_);
378 new StatusAreaWidget(wm_status_container, wm_shelf_aura_);
379 status_area_widget_->CreateTrayViews(); 320 status_area_widget_->CreateTrayViews();
380 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) 321 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted())
381 status_area_widget_->Show(); 322 status_area_widget_->Show();
382 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); 323 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_);
383 background_animator_.AddObserver(status_area_widget_); 324 background_animator_.AddObserver(status_area_widget_);
384 wm_status_container->SetLayoutManager( 325 status_container->SetLayoutManager(
385 base::MakeUnique<StatusAreaLayoutManager>(this)); 326 base::MakeUnique<StatusAreaLayoutManager>(this));
386 327
387 aura::Window* shelf_container = 328 WmWindowAura::GetAuraWindow(shelf_container)->SetEventTargeter(
388 WmWindowAura::GetAuraWindow(wm_shelf_container); 329 base::MakeUnique<ShelfWindowTargeter>(shelf_container, wm_shelf_aura_));
389 aura::Window* status_container = 330 WmWindowAura::GetAuraWindow(status_container)->SetEventTargeter(
390 WmWindowAura::GetAuraWindow(wm_status_container); 331 base::MakeUnique<ShelfWindowTargeter>(status_container, wm_shelf_aura_));
391 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
392 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_)));
393 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
394 new ShelfWindowTargeter(status_container, shelf_layout_manager_)));
395 332
396 views::Widget::AddObserver(this); 333 views::Widget::AddObserver(this);
397 } 334 }
398 335
399 ShelfWidget::~ShelfWidget() { 336 ShelfWidget::~ShelfWidget() {
400 // Must call Shutdown() before destruction. 337 // Must call Shutdown() before destruction.
401 DCHECK(!status_area_widget_); 338 DCHECK(!status_area_widget_);
402 WmShell::Get()->focus_cycler()->RemoveWidget(this); 339 WmShell::Get()->focus_cycler()->RemoveWidget(this);
403 SetFocusCycler(nullptr); 340 SetFocusCycler(nullptr);
404 RemoveObserver(this); 341 RemoveObserver(this);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); 532 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event);
596 } 533 }
597 534
598 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { 535 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) {
599 Widget::OnGestureEvent(event); 536 Widget::OnGestureEvent(event);
600 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) 537 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_)
601 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); 538 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event);
602 } 539 }
603 540
604 } // namespace ash 541 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_widget.h ('k') | ash/shelf/shelf_window_targeter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698