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

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

Issue 11451002: Focus launcher if spoken feedback is enabled and no other windows visible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests. Created 8 years 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
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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "ash/focus_cycler.h" 10 #include "ash/focus_cycler.h"
11 #include "ash/launcher/launcher_delegate.h" 11 #include "ash/launcher/launcher_delegate.h"
12 #include "ash/launcher/launcher_model.h" 12 #include "ash/launcher/launcher_model.h"
13 #include "ash/launcher/launcher_navigator.h" 13 #include "ash/launcher/launcher_navigator.h"
14 #include "ash/launcher/launcher_view.h" 14 #include "ash/launcher/launcher_view.h"
15 #include "ash/root_window_controller.h" 15 #include "ash/root_window_controller.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/shell_delegate.h" 17 #include "ash/shell_delegate.h"
18 #include "ash/shell_window_ids.h" 18 #include "ash/shell_window_ids.h"
19 #include "ash/wm/shelf_layout_manager.h" 19 #include "ash/wm/shelf_layout_manager.h"
20 #include "ash/wm/window_properties.h" 20 #include "ash/wm/window_properties.h"
21 #include "grit/ash_resources.h" 21 #include "grit/ash_resources.h"
22 #include "ui/aura/client/activation_client.h"
22 #include "ui/aura/root_window.h" 23 #include "ui/aura/root_window.h"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
24 #include "ui/aura/window_observer.h" 25 #include "ui/aura/window_observer.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/compositor/layer.h" 27 #include "ui/compositor/layer.h"
27 #include "ui/gfx/canvas.h" 28 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/image/image.h" 29 #include "ui/gfx/image/image.h"
29 #include "ui/views/accessible_pane_view.h" 30 #include "ui/views/accessible_pane_view.h"
30 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_delegate.h" 32 #include "ui/views/widget/widget_delegate.h"
(...skipping 29 matching lines...) Expand all
61 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 62 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
62 63
63 // views::WidgetDelegateView overrides: 64 // views::WidgetDelegateView overrides:
64 virtual views::Widget* GetWidget() OVERRIDE { 65 virtual views::Widget* GetWidget() OVERRIDE {
65 return View::GetWidget(); 66 return View::GetWidget();
66 } 67 }
67 virtual const views::Widget* GetWidget() const OVERRIDE { 68 virtual const views::Widget* GetWidget() const OVERRIDE {
68 return View::GetWidget(); 69 return View::GetWidget();
69 } 70 }
70 virtual bool CanActivate() const OVERRIDE { 71 virtual bool CanActivate() const OVERRIDE {
71 // We don't want mouse clicks to activate us, but we need to allow 72 // Allow to activate as fallback.
72 // activation when the user is using the keyboard (FocusCycler). 73 if (launcher_->activating_as_fallback_)
73 return focus_cycler_ && focus_cycler_->widget_activating() == GetWidget(); 74 return true;
75 // Allow to activate from the focus cycler.
76 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget())
77 return true;
78 // Disallow activating in other cases, especially when using mouse.
79 return false;
74 } 80 }
75 81
76 // BackgroundAnimatorDelegate overrides: 82 // BackgroundAnimatorDelegate overrides:
77 virtual void UpdateBackground(int alpha) OVERRIDE; 83 virtual void UpdateBackground(int alpha) OVERRIDE;
78 84
79 private: 85 private:
80 Launcher* launcher_; 86 Launcher* launcher_;
81 internal::FocusCycler* focus_cycler_; 87 internal::FocusCycler* focus_cycler_;
82 int alpha_; 88 int alpha_;
83 89
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 205
200 // Launcher -------------------------------------------------------------------- 206 // Launcher --------------------------------------------------------------------
201 207
202 Launcher::Launcher(aura::Window* window_container, 208 Launcher::Launcher(aura::Window* window_container,
203 internal::ShelfLayoutManager* shelf_layout_manager) 209 internal::ShelfLayoutManager* shelf_layout_manager)
204 : widget_(NULL), 210 : widget_(NULL),
205 window_container_(window_container), 211 window_container_(window_container),
206 delegate_view_(new DelegateView(this)), 212 delegate_view_(new DelegateView(this)),
207 launcher_view_(NULL), 213 launcher_view_(NULL),
208 alignment_(SHELF_ALIGNMENT_BOTTOM), 214 alignment_(SHELF_ALIGNMENT_BOTTOM),
209 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha) { 215 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha),
216 activating_as_fallback_(false) {
210 model_.reset(new LauncherModel); 217 model_.reset(new LauncherModel);
211 delegate_.reset( 218 delegate_.reset(
212 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get())); 219 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get()));
213 220
214 widget_.reset(new views::Widget); 221 widget_.reset(new views::Widget);
215 views::Widget::InitParams params( 222 views::Widget::InitParams params(
216 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 223 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
217 params.transparent = true; 224 params.transparent = true;
218 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 225 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
219 params.parent = Shell::GetContainer( 226 params.parent = Shell::GetContainer(
(...skipping 10 matching lines...) Expand all
230 widget_->set_focus_on_creation(false); 237 widget_->set_focus_on_creation(false);
231 widget_->SetContentsView(delegate_view_); 238 widget_->SetContentsView(delegate_view_);
232 widget_->GetNativeView()->SetName("LauncherView"); 239 widget_->GetNativeView()->SetName("LauncherView");
233 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, 240 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey,
234 true); 241 true);
235 242
236 // SetBounds() has to be called after kStayInSameRootWindowKey is set. 243 // SetBounds() has to be called after kStayInSameRootWindowKey is set.
237 gfx::Size pref = 244 gfx::Size pref =
238 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); 245 static_cast<views::View*>(launcher_view_)->GetPreferredSize();
239 widget_->SetBounds(gfx::Rect(pref)); 246 widget_->SetBounds(gfx::Rect(pref));
247
248 widget_->AddObserver(this);
240 } 249 }
241 250
242 Launcher::~Launcher() { 251 Launcher::~Launcher() {
252 widget_->RemoveObserver(this);
243 } 253 }
244 254
245 // static 255 // static
246 Launcher* Launcher::ForPrimaryDisplay() { 256 Launcher* Launcher::ForPrimaryDisplay() {
247 return internal::RootWindowController::ForLauncher( 257 return internal::RootWindowController::ForLauncher(
248 Shell::GetPrimaryRootWindow())->launcher(); 258 Shell::GetPrimaryRootWindow())->launcher();
249 } 259 }
250 260
251 // static 261 // static
252 Launcher* Launcher::ForWindow(aura::Window* window) { 262 Launcher* Launcher::ForWindow(aura::Window* window) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 views::View* Launcher::GetAppListButtonView() const { 381 views::View* Launcher::GetAppListButtonView() const {
372 return launcher_view_->GetAppListButtonView(); 382 return launcher_view_->GetAppListButtonView();
373 } 383 }
374 384
375 void Launcher::SetWidgetBounds(const gfx::Rect bounds) { 385 void Launcher::SetWidgetBounds(const gfx::Rect bounds) {
376 widget_->SetBounds(bounds); 386 widget_->SetBounds(bounds);
377 if (dimmer_.get()) 387 if (dimmer_.get())
378 dimmer_->SetBounds(bounds); 388 dimmer_->SetBounds(bounds);
379 } 389 }
380 390
391 void Launcher::OnWidgetActivationChanged(views::Widget* widget, bool active) {
sky 2012/12/10 15:37:51 This should be beneath GetLauncherViewForTest.
mtomasz 2012/12/11 05:03:32 Done.
392 activating_as_fallback_ = false;
393 if (active) {
394 delegate_view_->SetPaneFocusAndFocusDefault();
395 } else {
396 delegate_view_->GetFocusManager()->ClearFocus();
397 }
398 }
399
381 internal::LauncherView* Launcher::GetLauncherViewForTest() { 400 internal::LauncherView* Launcher::GetLauncherViewForTest() {
382 return launcher_view_; 401 return launcher_view_;
383 } 402 }
384 403
385 } // namespace ash 404 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698