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

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: Cleaned up the code. 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 Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) {
75 return true;
76 }
77 // Allow to activate from the focus cycler.
78 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget())
79 return true;
80 // Disallow activating in other cases, especially when using mouse.
81 return false;
74 } 82 }
75 83
76 // BackgroundAnimatorDelegate overrides: 84 // BackgroundAnimatorDelegate overrides:
77 virtual void UpdateBackground(int alpha) OVERRIDE; 85 virtual void UpdateBackground(int alpha) OVERRIDE;
78 86
79 private: 87 private:
80 Launcher* launcher_; 88 Launcher* launcher_;
81 internal::FocusCycler* focus_cycler_; 89 internal::FocusCycler* focus_cycler_;
82 int alpha_; 90 int alpha_;
83 91
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 205
198 // Launcher -------------------------------------------------------------------- 206 // Launcher --------------------------------------------------------------------
199 207
200 Launcher::Launcher(aura::Window* window_container, 208 Launcher::Launcher(aura::Window* window_container,
201 internal::ShelfLayoutManager* shelf_layout_manager) 209 internal::ShelfLayoutManager* shelf_layout_manager)
202 : widget_(NULL), 210 : widget_(NULL),
203 window_container_(window_container), 211 window_container_(window_container),
204 delegate_view_(new DelegateView(this)), 212 delegate_view_(new DelegateView(this)),
205 launcher_view_(NULL), 213 launcher_view_(NULL),
206 alignment_(SHELF_ALIGNMENT_BOTTOM), 214 alignment_(SHELF_ALIGNMENT_BOTTOM),
207 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha) { 215 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha),
216 activating_as_fallback_(false) {
208 model_.reset(new LauncherModel); 217 model_.reset(new LauncherModel);
209 delegate_.reset( 218 delegate_.reset(
210 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get())); 219 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get()));
211 220
212 widget_.reset(new views::Widget); 221 widget_.reset(new views::Widget);
213 views::Widget::InitParams params( 222 views::Widget::InitParams params(
214 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 223 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
215 params.transparent = true; 224 params.transparent = true;
216 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 225 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
217 params.parent = Shell::GetContainer( 226 params.parent = Shell::GetContainer(
218 window_container_->GetRootWindow(), 227 window_container_->GetRootWindow(),
219 ash::internal::kShellWindowId_LauncherContainer); 228 ash::internal::kShellWindowId_LauncherContainer);
220 launcher_view_ = new internal::LauncherView( 229 launcher_view_ = new internal::LauncherView(
221 model_.get(), delegate_.get(), shelf_layout_manager); 230 model_.get(), delegate_.get(), shelf_layout_manager);
222 launcher_view_->Init(); 231 launcher_view_->Init();
223 delegate_view_->AddChildView(launcher_view_); 232 delegate_view_->AddChildView(launcher_view_);
224 params.delegate = delegate_view_; 233 params.delegate = delegate_view_;
225 widget_->Init(params); 234 widget_->Init(params);
226 widget_->GetNativeWindow()->SetName("LauncherWindow"); 235 widget_->GetNativeWindow()->SetName("LauncherWindow");
227 // The launcher should not take focus when it is initially shown. 236 // The launcher should not take focus when it is initially shown.
228 widget_->set_focus_on_creation(false); 237 widget_->set_focus_on_creation(false);
229 widget_->SetContentsView(delegate_view_); 238 widget_->SetContentsView(delegate_view_);
230 widget_->GetNativeView()->SetName("LauncherView"); 239 widget_->GetNativeView()->SetName("LauncherView");
231 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, 240 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey,
232 true); 241 true);
233 // SetBounds() has to be called after kStayInSameRootWindowKey is set. 242 // SetBounds() has to be called after kStayInSameRootWindowKey is set.
234 gfx::Size pref = 243 gfx::Size pref =
235 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); 244 static_cast<views::View*>(launcher_view_)->GetPreferredSize();
236 widget_->SetBounds(gfx::Rect(pref)); 245 widget_->SetBounds(gfx::Rect(pref));
246
247 widget_->AddObserver(this);
237 } 248 }
238 249
239 Launcher::~Launcher() { 250 Launcher::~Launcher() {
251 widget_->RemoveObserver(this);
240 } 252 }
241 253
242 // static 254 // static
243 Launcher* Launcher::ForPrimaryDisplay() { 255 Launcher* Launcher::ForPrimaryDisplay() {
244 return internal::RootWindowController::ForLauncher( 256 return internal::RootWindowController::ForLauncher(
245 Shell::GetPrimaryRootWindow())->launcher(); 257 Shell::GetPrimaryRootWindow())->launcher();
246 } 258 }
247 259
248 // static 260 // static
249 Launcher* Launcher::ForWindow(aura::Window* window) { 261 Launcher* Launcher::ForWindow(aura::Window* window) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 views::View* Launcher::GetAppListButtonView() const { 380 views::View* Launcher::GetAppListButtonView() const {
369 return launcher_view_->GetAppListButtonView(); 381 return launcher_view_->GetAppListButtonView();
370 } 382 }
371 383
372 void Launcher::SetWidgetBounds(const gfx::Rect bounds) { 384 void Launcher::SetWidgetBounds(const gfx::Rect bounds) {
373 widget_->SetBounds(bounds); 385 widget_->SetBounds(bounds);
374 if (dimmer_.get()) 386 if (dimmer_.get())
375 dimmer_->SetBounds(bounds); 387 dimmer_->SetBounds(bounds);
376 } 388 }
377 389
390 void Launcher::OnWidgetActivationChanged(views::Widget* widget, bool active) {
391 activating_as_fallback_ = false;
392 if (active) {
393 delegate_view_->SetPaneFocusAndFocusDefault();
394 } else {
395 delegate_view_->GetFocusManager()->ClearFocus();
396 }
397 }
398
378 internal::LauncherView* Launcher::GetLauncherViewForTest() { 399 internal::LauncherView* Launcher::GetLauncherViewForTest() {
379 return launcher_view_; 400 return launcher_view_;
380 } 401 }
381 402
382 } // namespace ash 403 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698