| 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" | |
| 23 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
| 24 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 25 #include "ui/aura/window_observer.h" | 24 #include "ui/aura/window_observer.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
| 28 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 30 #include "ui/views/accessible_pane_view.h" | 29 #include "ui/views/accessible_pane_view.h" |
| 31 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 32 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; | 61 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; |
| 63 | 62 |
| 64 // views::WidgetDelegateView overrides: | 63 // views::WidgetDelegateView overrides: |
| 65 virtual views::Widget* GetWidget() OVERRIDE { | 64 virtual views::Widget* GetWidget() OVERRIDE { |
| 66 return View::GetWidget(); | 65 return View::GetWidget(); |
| 67 } | 66 } |
| 68 virtual const views::Widget* GetWidget() const OVERRIDE { | 67 virtual const views::Widget* GetWidget() const OVERRIDE { |
| 69 return View::GetWidget(); | 68 return View::GetWidget(); |
| 70 } | 69 } |
| 71 virtual bool CanActivate() const OVERRIDE { | 70 virtual bool CanActivate() const OVERRIDE { |
| 72 // Allow to activate as fallback. | 71 // We don't want mouse clicks to activate us, but we need to allow |
| 73 if (launcher_->activating_as_fallback_) | 72 // activation when the user is using the keyboard (FocusCycler). |
| 74 return true; | 73 return focus_cycler_ && focus_cycler_->widget_activating() == GetWidget(); |
| 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; | |
| 80 } | 74 } |
| 81 | 75 |
| 82 // BackgroundAnimatorDelegate overrides: | 76 // BackgroundAnimatorDelegate overrides: |
| 83 virtual void UpdateBackground(int alpha) OVERRIDE; | 77 virtual void UpdateBackground(int alpha) OVERRIDE; |
| 84 | 78 |
| 85 private: | 79 private: |
| 86 Launcher* launcher_; | 80 Launcher* launcher_; |
| 87 internal::FocusCycler* focus_cycler_; | 81 internal::FocusCycler* focus_cycler_; |
| 88 int alpha_; | 82 int alpha_; |
| 89 | 83 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 Launcher::Launcher(LauncherModel* launcher_model, | 202 Launcher::Launcher(LauncherModel* launcher_model, |
| 209 LauncherDelegate* launcher_delegate, | 203 LauncherDelegate* launcher_delegate, |
| 210 aura::Window* window_container, | 204 aura::Window* window_container, |
| 211 internal::ShelfLayoutManager* shelf_layout_manager) | 205 internal::ShelfLayoutManager* shelf_layout_manager) |
| 212 : widget_(NULL), | 206 : widget_(NULL), |
| 213 window_container_(window_container), | 207 window_container_(window_container), |
| 214 delegate_view_(new DelegateView(this)), | 208 delegate_view_(new DelegateView(this)), |
| 215 launcher_view_(NULL), | 209 launcher_view_(NULL), |
| 216 alignment_(SHELF_ALIGNMENT_BOTTOM), | 210 alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 217 delegate_(launcher_delegate), | 211 delegate_(launcher_delegate), |
| 218 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha), | 212 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha) { |
| 219 activating_as_fallback_(false) { | |
| 220 widget_.reset(new views::Widget); | 213 widget_.reset(new views::Widget); |
| 221 views::Widget::InitParams params( | 214 views::Widget::InitParams params( |
| 222 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 215 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 223 params.transparent = true; | 216 params.transparent = true; |
| 224 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 217 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 225 params.parent = Shell::GetContainer( | 218 params.parent = Shell::GetContainer( |
| 226 window_container_->GetRootWindow(), | 219 window_container_->GetRootWindow(), |
| 227 ash::internal::kShellWindowId_LauncherContainer); | 220 ash::internal::kShellWindowId_LauncherContainer); |
| 228 launcher_view_ = new internal::LauncherView( | 221 launcher_view_ = new internal::LauncherView( |
| 229 launcher_model, delegate_, shelf_layout_manager); | 222 launcher_model, delegate_, shelf_layout_manager); |
| 230 launcher_view_->Init(); | 223 launcher_view_->Init(); |
| 231 delegate_view_->AddChildView(launcher_view_); | 224 delegate_view_->AddChildView(launcher_view_); |
| 232 params.delegate = delegate_view_; | 225 params.delegate = delegate_view_; |
| 233 widget_->Init(params); | 226 widget_->Init(params); |
| 234 widget_->GetNativeWindow()->SetName("LauncherWindow"); | 227 widget_->GetNativeWindow()->SetName("LauncherWindow"); |
| 235 // The launcher should not take focus when it is initially shown. | 228 // The launcher should not take focus when it is initially shown. |
| 236 widget_->set_focus_on_creation(false); | 229 widget_->set_focus_on_creation(false); |
| 237 widget_->SetContentsView(delegate_view_); | 230 widget_->SetContentsView(delegate_view_); |
| 238 widget_->GetNativeView()->SetName("LauncherView"); | 231 widget_->GetNativeView()->SetName("LauncherView"); |
| 239 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, | 232 widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, |
| 240 true); | 233 true); |
| 241 | 234 |
| 242 // SetBounds() has to be called after kStayInSameRootWindowKey is set. | 235 // SetBounds() has to be called after kStayInSameRootWindowKey is set. |
| 243 gfx::Size pref = | 236 gfx::Size pref = |
| 244 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); | 237 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); |
| 245 widget_->SetBounds(gfx::Rect(pref)); | 238 widget_->SetBounds(gfx::Rect(pref)); |
| 246 | |
| 247 widget_->AddObserver(this); | |
| 248 } | 239 } |
| 249 | 240 |
| 250 Launcher::~Launcher() { | 241 Launcher::~Launcher() { |
| 251 widget_->RemoveObserver(this); | |
| 252 } | 242 } |
| 253 | 243 |
| 254 // static | 244 // static |
| 255 Launcher* Launcher::ForPrimaryDisplay() { | 245 Launcher* Launcher::ForPrimaryDisplay() { |
| 256 return internal::RootWindowController::ForLauncher( | 246 return internal::RootWindowController::ForLauncher( |
| 257 Shell::GetPrimaryRootWindow())->launcher(); | 247 Shell::GetPrimaryRootWindow())->launcher(); |
| 258 } | 248 } |
| 259 | 249 |
| 260 // static | 250 // static |
| 261 Launcher* Launcher::ForWindow(aura::Window* window) { | 251 Launcher* Launcher::ForWindow(aura::Window* window) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // found (which is true when indexes_left is -1) or b.) the last item was | 399 // found (which is true when indexes_left is -1) or b.) the last item was |
| 410 // requested (which is true when index was passed in as a negative number). | 400 // requested (which is true when index was passed in as a negative number). |
| 411 if (found_index >= 0 && (indexes_left == -1 || window_index < 0) && | 401 if (found_index >= 0 && (indexes_left == -1 || window_index < 0) && |
| 412 (items[found_index].status == ash::STATUS_RUNNING || | 402 (items[found_index].status == ash::STATUS_RUNNING || |
| 413 items[found_index].status == ash::STATUS_CLOSED)) { | 403 items[found_index].status == ash::STATUS_CLOSED)) { |
| 414 // Then set this one as active. | 404 // Then set this one as active. |
| 415 ActivateLauncherItem(found_index); | 405 ActivateLauncherItem(found_index); |
| 416 } | 406 } |
| 417 } | 407 } |
| 418 | 408 |
| 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 | |
| 428 internal::LauncherView* Launcher::GetLauncherViewForTest() { | 409 internal::LauncherView* Launcher::GetLauncherViewForTest() { |
| 429 return launcher_view_; | 410 return launcher_view_; |
| 430 } | 411 } |
| 431 | 412 |
| 432 } // namespace ash | 413 } // namespace ash |
| OLD | NEW |