| OLD | NEW |
| 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 Loading... |
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 Launcher::Launcher(LauncherModel* launcher_model, | 208 Launcher::Launcher(LauncherModel* launcher_model, |
| 203 LauncherDelegate* launcher_delegate, | 209 LauncherDelegate* launcher_delegate, |
| 204 aura::Window* window_container, | 210 aura::Window* window_container, |
| 205 internal::ShelfLayoutManager* shelf_layout_manager) | 211 internal::ShelfLayoutManager* shelf_layout_manager) |
| 206 : widget_(NULL), | 212 : widget_(NULL), |
| 207 window_container_(window_container), | 213 window_container_(window_container), |
| 208 delegate_view_(new DelegateView(this)), | 214 delegate_view_(new DelegateView(this)), |
| 209 launcher_view_(NULL), | 215 launcher_view_(NULL), |
| 210 alignment_(SHELF_ALIGNMENT_BOTTOM), | 216 alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 211 delegate_(launcher_delegate), | 217 delegate_(launcher_delegate), |
| 212 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha) { | 218 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha), |
| 219 activating_as_fallback_(false) { |
| 213 widget_.reset(new views::Widget); | 220 widget_.reset(new views::Widget); |
| 214 views::Widget::InitParams params( | 221 views::Widget::InitParams params( |
| 215 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 222 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 216 params.transparent = true; | 223 params.transparent = true; |
| 217 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 224 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 218 params.parent = Shell::GetContainer( | 225 params.parent = Shell::GetContainer( |
| 219 window_container_->GetRootWindow(), | 226 window_container_->GetRootWindow(), |
| 220 ash::internal::kShellWindowId_LauncherContainer); | 227 ash::internal::kShellWindowId_LauncherContainer); |
| 221 launcher_view_ = new internal::LauncherView( | 228 launcher_view_ = new internal::LauncherView( |
| 222 launcher_model, delegate_, shelf_layout_manager); | 229 launcher_model, delegate_, shelf_layout_manager); |
| 223 launcher_view_->Init(); | 230 launcher_view_->Init(); |
| 224 delegate_view_->AddChildView(launcher_view_); | 231 delegate_view_->AddChildView(launcher_view_); |
| 225 params.delegate = delegate_view_; | 232 params.delegate = delegate_view_; |
| 226 widget_->Init(params); | 233 widget_->Init(params); |
| 227 widget_->GetNativeWindow()->SetName("LauncherWindow"); | 234 widget_->GetNativeWindow()->SetName("LauncherWindow"); |
| 228 // The launcher should not take focus when it is initially shown. | 235 // The launcher should not take focus when it is initially shown. |
| 229 widget_->set_focus_on_creation(false); | 236 widget_->set_focus_on_creation(false); |
| 230 widget_->SetContentsView(delegate_view_); | 237 widget_->SetContentsView(delegate_view_); |
| 231 widget_->GetNativeView()->SetName("LauncherView"); | 238 widget_->GetNativeView()->SetName("LauncherView"); |
| 232 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, | 239 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, |
| 233 true); | 240 true); |
| 234 | 241 |
| 235 // SetBounds() has to be called after kStayInSameRootWindowKey is set. | 242 // SetBounds() has to be called after kStayInSameRootWindowKey is set. |
| 236 gfx::Size pref = | 243 gfx::Size pref = |
| 237 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); | 244 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); |
| 238 widget_->SetBounds(gfx::Rect(pref)); | 245 widget_->SetBounds(gfx::Rect(pref)); |
| 246 |
| 247 widget_->AddObserver(this); |
| 239 } | 248 } |
| 240 | 249 |
| 241 Launcher::~Launcher() { | 250 Launcher::~Launcher() { |
| 251 widget_->RemoveObserver(this); |
| 242 } | 252 } |
| 243 | 253 |
| 244 // static | 254 // static |
| 245 Launcher* Launcher::ForPrimaryDisplay() { | 255 Launcher* Launcher::ForPrimaryDisplay() { |
| 246 return internal::RootWindowController::ForLauncher( | 256 return internal::RootWindowController::ForLauncher( |
| 247 Shell::GetPrimaryRootWindow())->launcher(); | 257 Shell::GetPrimaryRootWindow())->launcher(); |
| 248 } | 258 } |
| 249 | 259 |
| 250 // static | 260 // static |
| 251 Launcher* Launcher::ForWindow(aura::Window* window) { | 261 Launcher* Launcher::ForWindow(aura::Window* window) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 // found (which is true when indexes_left is -1) or b.) the last item was | 409 // found (which is true when indexes_left is -1) or b.) the last item was |
| 400 // requested (which is true when index was passed in as a negative number). | 410 // requested (which is true when index was passed in as a negative number). |
| 401 if (found_index >= 0 && (indexes_left == -1 || window_index < 0) && | 411 if (found_index >= 0 && (indexes_left == -1 || window_index < 0) && |
| 402 (items[found_index].status == ash::STATUS_RUNNING || | 412 (items[found_index].status == ash::STATUS_RUNNING || |
| 403 items[found_index].status == ash::STATUS_CLOSED)) { | 413 items[found_index].status == ash::STATUS_CLOSED)) { |
| 404 // Then set this one as active. | 414 // Then set this one as active. |
| 405 ActivateLauncherItem(found_index); | 415 ActivateLauncherItem(found_index); |
| 406 } | 416 } |
| 407 } | 417 } |
| 408 | 418 |
| 419 void Launcher::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
| 420 activating_as_fallback_ = false; |
| 421 if (active) { |
| 422 delegate_view_->SetPaneFocusAndFocusDefault(); |
| 423 } else { |
| 424 delegate_view_->GetFocusManager()->ClearFocus(); |
| 425 } |
| 426 } |
| 427 |
| 409 internal::LauncherView* Launcher::GetLauncherViewForTest() { | 428 internal::LauncherView* Launcher::GetLauncherViewForTest() { |
| 410 return launcher_view_; | 429 return launcher_view_; |
| 411 } | 430 } |
| 412 | 431 |
| 413 } // namespace ash | 432 } // namespace ash |
| OLD | NEW |