| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/toolbar/app_menu_button.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/themes/theme_properties.h" | 11 #include "chrome/browser/themes/theme_properties.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 13 #include "chrome/browser/ui/toolbar/app_menu_model.h" |
| 14 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 14 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 15 #include "chrome/browser/ui/views/layout_constants.h" | 15 #include "chrome/browser/ui/views/layout_constants.h" |
| 16 #include "chrome/browser/ui/views/toolbar/app_menu.h" | 16 #include "chrome/browser/ui/views/toolbar/app_menu.h" |
| 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 18 #include "extensions/common/feature_switch.h" | 18 #include "extensions/common/feature_switch.h" |
| 19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 20 #include "ui/base/resource/material_design/material_design_controller.h" | 20 #include "ui/base/resource/material_design/material_design_controller.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/base/theme_provider.h" | 22 #include "ui/base/theme_provider.h" |
| 23 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
| 24 #include "ui/gfx/paint_vector_icon.h" | 24 #include "ui/gfx/paint_vector_icon.h" |
| 25 #include "ui/gfx/vector_icons_public.h" | 25 #include "ui/gfx/vector_icons_public.h" |
| 26 #include "ui/keyboard/keyboard_controller.h" | 26 #include "ui/keyboard/keyboard_controller.h" |
| 27 #include "ui/views/animation/ink_drop_animation_controller.h" | 27 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 28 #include "ui/views/animation/ink_drop_animation_controller_factory.h" | |
| 29 #include "ui/views/controls/button/label_button_border.h" | 28 #include "ui/views/controls/button/label_button_border.h" |
| 30 #include "ui/views/controls/menu/menu_listener.h" | 29 #include "ui/views/controls/menu/menu_listener.h" |
| 31 #include "ui/views/metrics.h" | 30 #include "ui/views/metrics.h" |
| 32 #include "ui/views/painter.h" | 31 #include "ui/views/painter.h" |
| 33 | 32 |
| 34 // static | 33 // static |
| 35 bool AppMenuButton::g_open_app_immediately_for_testing = false; | 34 bool AppMenuButton::g_open_app_immediately_for_testing = false; |
| 36 | 35 |
| 37 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) | 36 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) |
| 38 : views::MenuButton(NULL, base::string16(), toolbar_view, false), | 37 : views::MenuButton(NULL, base::string16(), toolbar_view, false), |
| 39 severity_(AppMenuIconPainter::SEVERITY_NONE), | 38 severity_(AppMenuIconPainter::SEVERITY_NONE), |
| 40 ink_drop_animation_controller_( | |
| 41 views::InkDropAnimationControllerFactory:: | |
| 42 CreateInkDropAnimationController(this)), | |
| 43 toolbar_view_(toolbar_view), | 39 toolbar_view_(toolbar_view), |
| 44 allow_extension_dragging_( | 40 allow_extension_dragging_( |
| 45 extensions::FeatureSwitch::extension_action_redesign() | 41 extensions::FeatureSwitch::extension_action_redesign() |
| 46 ->IsEnabled()), | 42 ->IsEnabled()), |
| 47 destroyed_(nullptr), | 43 destroyed_(nullptr), |
| 48 margin_trailing_(0), | 44 margin_trailing_(0), |
| 49 weak_factory_(this) { | 45 weak_factory_(this) { |
| 46 scoped_ptr<views::InkDropDelegate> new_ink_drop_delegate( |
| 47 new views::ButtonInkDropDelegate(this, this)); |
| 48 SetInkDropDelegate(new_ink_drop_delegate.Pass()); |
| 50 if (!ui::MaterialDesignController::IsModeMaterial()) | 49 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 51 icon_painter_.reset(new AppMenuIconPainter(this)); | 50 icon_painter_.reset(new AppMenuIconPainter(this)); |
| 52 | 51 |
| 53 const int kInkDropLargeSize = 32; | 52 const int kInkDropLargeSize = 32; |
| 54 const int kInkDropLargeCornerRadius = 5; | 53 const int kInkDropLargeCornerRadius = 5; |
| 55 const int kInkDropSmallSize = 24; | 54 const int kInkDropSmallSize = 24; |
| 56 const int kInkDropSmallCornerRadius = 2; | 55 const int kInkDropSmallCornerRadius = 2; |
| 57 | 56 |
| 58 ink_drop_animation_controller_->SetInkDropSize( | 57 ink_drop_delegate()->SetInkDropSize( |
| 59 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), | 58 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize, |
| 60 kInkDropLargeCornerRadius, | |
| 61 gfx::Size(kInkDropSmallSize, kInkDropSmallSize), | |
| 62 kInkDropSmallCornerRadius); | 59 kInkDropSmallCornerRadius); |
| 63 } | 60 } |
| 64 | 61 |
| 65 AppMenuButton::~AppMenuButton() { | 62 AppMenuButton::~AppMenuButton() { |
| 66 if (destroyed_) | 63 if (destroyed_) |
| 67 *destroyed_ = true; | 64 *destroyed_ = true; |
| 68 } | 65 } |
| 69 | 66 |
| 70 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity, | 67 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity, |
| 71 bool animate) { | 68 bool animate) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 101 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); | 98 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); |
| 102 | 99 |
| 103 // Because running the menu below spins a nested message loop, |this| can be | 100 // Because running the menu below spins a nested message loop, |this| can be |
| 104 // deleted by the time RunMenu() returns. To detect this, we set |destroyed_| | 101 // deleted by the time RunMenu() returns. To detect this, we set |destroyed_| |
| 105 // (which is normally null) to point to a local. If our destructor runs during | 102 // (which is normally null) to point to a local. If our destructor runs during |
| 106 // RunMenu(), then this local will be set to true on return, and we'll know | 103 // RunMenu(), then this local will be set to true on return, and we'll know |
| 107 // it's not safe to access any member variables. | 104 // it's not safe to access any member variables. |
| 108 bool destroyed = false; | 105 bool destroyed = false; |
| 109 destroyed_ = &destroyed; | 106 destroyed_ = &destroyed; |
| 110 | 107 |
| 111 ink_drop_animation_controller_->AnimateToState( | 108 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); |
| 112 views::InkDropState::ACTIVATED); | |
| 113 menu_->RunMenu(this); | 109 menu_->RunMenu(this); |
| 114 | 110 |
| 115 if (!destroyed) { | 111 if (!destroyed) { |
| 116 ink_drop_animation_controller_->AnimateToState( | 112 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED); |
| 117 views::InkDropState::DEACTIVATED); | |
| 118 destroyed_ = nullptr; | 113 destroyed_ = nullptr; |
| 119 } | 114 } |
| 120 } | 115 } |
| 121 | 116 |
| 122 void AppMenuButton::CloseMenu() { | 117 void AppMenuButton::CloseMenu() { |
| 123 if (menu_) | 118 if (menu_) |
| 124 menu_->CloseMenu(); | 119 menu_->CloseMenu(); |
| 125 menu_.reset(); | 120 menu_.reset(); |
| 126 } | 121 } |
| 127 | 122 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 views::View::AreDropTypesRequired(); | 256 views::View::AreDropTypesRequired(); |
| 262 } | 257 } |
| 263 | 258 |
| 264 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { | 259 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { |
| 265 return allow_extension_dragging_ ? | 260 return allow_extension_dragging_ ? |
| 266 BrowserActionDragData::CanDrop(data, | 261 BrowserActionDragData::CanDrop(data, |
| 267 toolbar_view_->browser()->profile()) : | 262 toolbar_view_->browser()->profile()) : |
| 268 views::View::CanDrop(data); | 263 views::View::CanDrop(data); |
| 269 } | 264 } |
| 270 | 265 |
| 271 void AppMenuButton::Layout() { | |
| 272 MenuButton::Layout(); | |
| 273 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); | |
| 274 } | |
| 275 | |
| 276 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { | 266 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { |
| 277 DCHECK(allow_extension_dragging_); | 267 DCHECK(allow_extension_dragging_); |
| 278 DCHECK(!weak_factory_.HasWeakPtrs()); | 268 DCHECK(!weak_factory_.HasWeakPtrs()); |
| 279 if (!g_open_app_immediately_for_testing) { | 269 if (!g_open_app_immediately_for_testing) { |
| 280 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 270 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 281 FROM_HERE, | 271 FROM_HERE, |
| 282 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), | 272 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), |
| 283 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 273 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
| 284 } else { | 274 } else { |
| 285 ShowMenu(true); | 275 ShowMenu(true); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 305 views::MenuButton::OnPaint(canvas); | 295 views::MenuButton::OnPaint(canvas); |
| 306 if (ui::MaterialDesignController::IsModeMaterial()) | 296 if (ui::MaterialDesignController::IsModeMaterial()) |
| 307 return; | 297 return; |
| 308 // Use GetPreferredSize() to center the icon inside the visible bounds rather | 298 // Use GetPreferredSize() to center the icon inside the visible bounds rather |
| 309 // than the whole size() (which may refer to hit test region extended to the | 299 // than the whole size() (which may refer to hit test region extended to the |
| 310 // end of the toolbar in maximized mode). | 300 // end of the toolbar in maximized mode). |
| 311 icon_painter_->Paint(canvas, GetThemeProvider(), | 301 icon_painter_->Paint(canvas, GetThemeProvider(), |
| 312 gfx::Rect(GetPreferredSize()), | 302 gfx::Rect(GetPreferredSize()), |
| 313 AppMenuIconPainter::BEZEL_NONE); | 303 AppMenuIconPainter::BEZEL_NONE); |
| 314 } | 304 } |
| OLD | NEW |