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

Side by Side Diff: ash/launcher/launcher.cc

Issue 9817026: Changes how we detect whether the launcher should be shown when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/system/tray/system_tray.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 (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/launcher/launcher.h" 5 #include "ash/launcher/launcher.h"
6 6
7 #include "ash/focus_cycler.h" 7 #include "ash/focus_cycler.h"
8 #include "ash/launcher/launcher_delegate.h" 8 #include "ash/launcher/launcher_delegate.h"
9 #include "ash/launcher/launcher_model.h" 9 #include "ash/launcher/launcher_model.h"
10 #include "ash/launcher/launcher_view.h" 10 #include "ash/launcher/launcher_view.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_delegate.h" 12 #include "ash/shell_delegate.h"
13 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
14 #include "ash/wm/shelf_layout_manager.h" 14 #include "ash/wm/shelf_layout_manager.h"
15 #include "base/timer.h"
16 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
17 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/compositor/layer.h" 17 #include "ui/gfx/compositor/layer.h"
19 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
20 #include "ui/views/accessible_pane_view.h" 19 #include "ui/views/accessible_pane_view.h"
21 #include "ui/views/background.h" 20 #include "ui/views/background.h"
22 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h" 22 #include "ui/views/widget/widget_delegate.h"
24 23
25 namespace ash { 24 namespace ash {
26 25
27 namespace { 26 namespace {
28 27
29 // Delay before showing the launcher after the mouse enters the view.
30 const int kShowDelayMS = 300;
31
32 // Max alpha of the background. 28 // Max alpha of the background.
33 const int kBackgroundAlpha = 128; 29 const int kBackgroundAlpha = 128;
34 30
35 } 31 }
36 32
37 // The contents view of the Widget. This view contains LauncherView and 33 // The contents view of the Widget. This view contains LauncherView and
38 // sizes it to the width of the widget minus the size of the status area. 34 // sizes it to the width of the widget minus the size of the status area.
39 class Launcher::DelegateView : public views::WidgetDelegate, 35 class Launcher::DelegateView : public views::WidgetDelegate,
40 public views::AccessiblePaneView{ 36 public views::AccessiblePaneView{
41 public: 37 public:
42 explicit DelegateView(Launcher* launcher); 38 explicit DelegateView(Launcher* launcher);
43 virtual ~DelegateView(); 39 virtual ~DelegateView();
44 40
45 void SetStatusWidth(int width); 41 void SetStatusWidth(int width);
46 int status_width() const { return status_width_; } 42 int status_width() const { return status_width_; }
47 43
48 void set_focus_cycler(const internal::FocusCycler* focus_cycler) { 44 void set_focus_cycler(const internal::FocusCycler* focus_cycler) {
49 focus_cycler_ = focus_cycler; 45 focus_cycler_ = focus_cycler;
50 } 46 }
51 47
52 // views::View overrides 48 // views::View overrides
53 virtual gfx::Size GetPreferredSize() OVERRIDE; 49 virtual gfx::Size GetPreferredSize() OVERRIDE;
54 virtual void Layout() OVERRIDE; 50 virtual void Layout() OVERRIDE;
55 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
56 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
57 51
58 // views::WidgetDelegateView overrides: 52 // views::WidgetDelegateView overrides:
59 virtual views::Widget* GetWidget() OVERRIDE { 53 virtual views::Widget* GetWidget() OVERRIDE {
60 return View::GetWidget(); 54 return View::GetWidget();
61 } 55 }
62 virtual const views::Widget* GetWidget() const OVERRIDE { 56 virtual const views::Widget* GetWidget() const OVERRIDE {
63 return View::GetWidget(); 57 return View::GetWidget();
64 } 58 }
65 virtual bool CanActivate() const OVERRIDE { 59 virtual bool CanActivate() const OVERRIDE {
66 // We don't want mouse clicks to activate us, but we need to allow 60 // We don't want mouse clicks to activate us, but we need to allow
67 // activation when the user is using the keyboard (FocusCycler). 61 // activation when the user is using the keyboard (FocusCycler).
68 return focus_cycler_ && focus_cycler_->widget_activating() == GetWidget(); 62 return focus_cycler_ && focus_cycler_->widget_activating() == GetWidget();
69 } 63 }
70 64
71 private: 65 private:
72 // Shows the launcher.
73 void ShowLauncher();
74
75 Launcher* launcher_; 66 Launcher* launcher_;
76 67
77 // Width of the status area. 68 // Width of the status area.
78 int status_width_; 69 int status_width_;
79 70
80 const internal::FocusCycler* focus_cycler_; 71 const internal::FocusCycler* focus_cycler_;
81 72
82 base::OneShotTimer<DelegateView> show_timer_;
83
84 DISALLOW_COPY_AND_ASSIGN(DelegateView); 73 DISALLOW_COPY_AND_ASSIGN(DelegateView);
85 }; 74 };
86 75
87 Launcher::DelegateView::DelegateView(Launcher* launcher) 76 Launcher::DelegateView::DelegateView(Launcher* launcher)
88 : launcher_(launcher), 77 : launcher_(launcher),
89 status_width_(0), 78 status_width_(0),
90 focus_cycler_(NULL) { 79 focus_cycler_(NULL) {
91 set_notify_enter_exit_on_child(true);
92 } 80 }
93 81
94 Launcher::DelegateView::~DelegateView() { 82 Launcher::DelegateView::~DelegateView() {
95 } 83 }
96 84
97 void Launcher::DelegateView::SetStatusWidth(int width) { 85 void Launcher::DelegateView::SetStatusWidth(int width) {
98 if (status_width_ == width) 86 if (status_width_ == width)
99 return; 87 return;
100 88
101 status_width_ = width; 89 status_width_ = width;
102 Layout(); 90 Layout();
103 } 91 }
104 92
105 gfx::Size Launcher::DelegateView::GetPreferredSize() { 93 gfx::Size Launcher::DelegateView::GetPreferredSize() {
106 return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size(); 94 return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size();
107 } 95 }
108 96
109 void Launcher::DelegateView::Layout() { 97 void Launcher::DelegateView::Layout() {
110 if (child_count() == 0) 98 if (child_count() == 0)
111 return; 99 return;
112 child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height()); 100 child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height());
113 } 101 }
114 102
115 void Launcher::DelegateView::OnMouseEntered(const views::MouseEvent& event) {
116 if (!show_timer_.IsRunning()) {
117 // The user may be trying to target a button near the bottom of the screen
118 // and accidentally moved into the launcher area. Delay showing.
119 show_timer_.Start(FROM_HERE,
120 base::TimeDelta::FromMilliseconds(kShowDelayMS),
121 this, &DelegateView::ShowLauncher);
122 }
123 }
124
125 void Launcher::DelegateView::OnMouseExited(const views::MouseEvent& event) {
126 show_timer_.Stop();
127 internal::ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
128 shelf->SetState(shelf->visibility_state(),
129 internal::ShelfLayoutManager::AUTO_HIDE_HIDDEN);
130 }
131
132 void Launcher::DelegateView::ShowLauncher() {
133 show_timer_.Stop();
134 internal::ShelfLayoutManager* shelf = Shell::GetInstance()->shelf();
135 shelf->SetState(shelf->visibility_state(),
136 internal::ShelfLayoutManager::AUTO_HIDE_SHOWN);
137 }
138
139
140 // Launcher -------------------------------------------------------------------- 103 // Launcher --------------------------------------------------------------------
141 104
142 Launcher::Launcher(aura::Window* window_container) 105 Launcher::Launcher(aura::Window* window_container)
143 : widget_(NULL), 106 : widget_(NULL),
144 window_container_(window_container), 107 window_container_(window_container),
145 delegate_view_(NULL), 108 delegate_view_(NULL),
146 launcher_view_(NULL), 109 launcher_view_(NULL),
147 ALLOW_THIS_IN_INITIALIZER_LIST( 110 ALLOW_THIS_IN_INITIALIZER_LIST(
148 background_animator_(this, 0, kBackgroundAlpha)) { 111 background_animator_(this, 0, kBackgroundAlpha)) {
149 model_.reset(new LauncherModel); 112 model_.reset(new LauncherModel);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (alpha == 0) { 188 if (alpha == 0) {
226 delegate_view_->set_background(NULL); 189 delegate_view_->set_background(NULL);
227 } else { 190 } else {
228 delegate_view_->set_background( 191 delegate_view_->set_background(
229 views::Background::CreateSolidBackground(0, 0, 0, alpha)); 192 views::Background::CreateSolidBackground(0, 0, 0, alpha));
230 } 193 }
231 delegate_view_->SchedulePaint(); 194 delegate_view_->SchedulePaint();
232 } 195 }
233 196
234 } // namespace ash 197 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/tray/system_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698