Chromium Code Reviews| 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/toolbar_button.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "chrome/browser/themes/theme_properties.h" | 11 #include "chrome/browser/themes/theme_properties.h" |
| 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 13 #include "ui/accessibility/ax_view_state.h" | 13 #include "ui/accessibility/ax_view_state.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/models/menu_model.h" | 15 #include "ui/base/models/menu_model.h" |
| 16 #include "ui/base/resource/material_design/material_design_controller.h" | 16 #include "ui/base/resource/material_design/material_design_controller.h" |
| 17 #include "ui/base/theme_provider.h" | 17 #include "ui/base/theme_provider.h" |
| 18 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| 19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 20 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
| 21 #include "ui/views/animation/ink_drop_animation_controller.h" | |
| 21 #include "ui/views/controls/button/label_button_border.h" | 22 #include "ui/views/controls/button/label_button_border.h" |
| 22 #include "ui/views/controls/menu/menu_item_view.h" | 23 #include "ui/views/controls/menu/menu_item_view.h" |
| 23 #include "ui/views/controls/menu/menu_model_adapter.h" | 24 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 24 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
| 25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 26 | 27 |
| 27 ToolbarButton::ToolbarButton(views::ButtonListener* listener, | 28 ToolbarButton::ToolbarButton(views::ButtonListener* listener, |
| 28 ui::MenuModel* model) | 29 ui::MenuModel* model) |
| 29 : views::LabelButton(listener, base::string16()), | 30 : views::LabelButton(listener, base::string16()), |
| 30 model_(model), | 31 model_(model), |
| 31 menu_showing_(false), | 32 menu_showing_(false), |
| 32 y_position_on_lbuttondown_(0), | 33 y_position_on_lbuttondown_(0), |
| 33 show_menu_factory_(this) { | 34 show_menu_factory_(this) { |
| 35 #if defined(OS_CHROMEOS) | |
|
Peter Kasting
2015/07/20 19:15:59
Can you at least add a comment here about why we'r
bruthig
2015/07/21 13:41:03
Done.
| |
| 36 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 37 ink_drop_animation_controller_.reset( | |
| 38 new views::InkDropAnimationController(this)); | |
| 39 layer()->SetFillsBoundsOpaquely(false); | |
| 40 image()->SetPaintToLayer(true); | |
| 41 image()->SetFillsBoundsOpaquely(false); | |
| 42 } | |
| 43 #endif // defined(OS_CHROMEOS) | |
| 44 | |
| 34 set_context_menu_controller(this); | 45 set_context_menu_controller(this); |
| 35 } | 46 } |
| 36 | 47 |
| 37 ToolbarButton::~ToolbarButton() { | 48 ToolbarButton::~ToolbarButton() { |
| 38 } | 49 } |
| 39 | 50 |
| 40 void ToolbarButton::Init() { | 51 void ToolbarButton::Init() { |
| 41 SetFocusable(false); | 52 SetFocusable(false); |
| 42 SetAccessibilityFocusable(true); | 53 SetAccessibilityFocusable(true); |
| 43 image()->EnableCanvasFlippingForRTLUI(true); | 54 image()->EnableCanvasFlippingForRTLUI(true); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; | 152 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; |
| 142 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 153 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); |
| 143 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 154 state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 144 } | 155 } |
| 145 | 156 |
| 146 scoped_ptr<views::LabelButtonBorder> | 157 scoped_ptr<views::LabelButtonBorder> |
| 147 ToolbarButton::CreateDefaultBorder() const { | 158 ToolbarButton::CreateDefaultBorder() const { |
| 148 scoped_ptr<views::LabelButtonBorder> border = | 159 scoped_ptr<views::LabelButtonBorder> border = |
| 149 LabelButton::CreateDefaultBorder(); | 160 LabelButton::CreateDefaultBorder(); |
| 150 | 161 |
| 162 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 163 // The material design spec does not include a visual effect for the | |
| 164 // STATE_HOVERED button state so we have to remove the default one added by | |
| 165 // LabelButton::CreateDefaultBorder(). | |
| 166 border->SetPainter(true, Button::STATE_HOVERED, nullptr); | |
| 167 border->SetPainter(false, Button::STATE_HOVERED, nullptr); | |
| 168 | |
| 169 #if defined(OS_CHROMEOS) | |
| 170 // The default STATE_PRESSED painters need to be removed so that they do not | |
| 171 // conflict with the ink drop ripple effect. | |
| 172 border->SetPainter(true, Button::STATE_PRESSED, nullptr); | |
| 173 border->SetPainter(false, Button::STATE_PRESSED, nullptr); | |
| 174 #endif // defined(OS_CHROMEOS) | |
| 175 } | |
| 176 | |
| 151 ui::ThemeProvider* provider = GetThemeProvider(); | 177 ui::ThemeProvider* provider = GetThemeProvider(); |
| 152 if (provider && provider->UsingSystemTheme()) { | 178 if (provider && provider->UsingSystemTheme()) { |
| 153 // Theme provided insets. | 179 // Theme provided insets. |
| 154 int inset = provider->GetDisplayProperty( | 180 int inset = provider->GetDisplayProperty( |
| 155 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); | 181 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); |
| 156 border->set_insets(gfx::Insets(inset, inset, inset, inset)); | 182 border->set_insets(gfx::Insets(inset, inset, inset, inset)); |
| 157 } | 183 } |
| 158 | 184 |
| 159 return border.Pass(); | 185 return border.Pass(); |
| 160 } | 186 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 SetMouseHandler(NULL); | 287 SetMouseHandler(NULL); |
| 262 | 288 |
| 263 // Set the state back to normal after the drop down menu is closed. | 289 // Set the state back to normal after the drop down menu is closed. |
| 264 if (state_ != STATE_DISABLED) | 290 if (state_ != STATE_DISABLED) |
| 265 SetState(STATE_NORMAL); | 291 SetState(STATE_NORMAL); |
| 266 } | 292 } |
| 267 | 293 |
| 268 const char* ToolbarButton::GetClassName() const { | 294 const char* ToolbarButton::GetClassName() const { |
| 269 return "ToolbarButton"; | 295 return "ToolbarButton"; |
| 270 } | 296 } |
| OLD | NEW |