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), |
| 34 ink_drop_animation_controller_(nullptr), | |
|
Peter Kasting
2015/07/17 18:01:58
Omit this.
bruthig
2015/07/20 14:53:07
Done.
| |
| 33 show_menu_factory_(this) { | 35 show_menu_factory_(this) { |
| 36 #if defined(OS_CHROMEOS) | |
|
Peter Kasting
2015/07/17 18:01:58
Why is this OS_CHROMEOS? Can't we do this for all
bruthig
2015/07/20 14:53:07
The designers want the ripple effect on Chrome OS
| |
| 37 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 38 ink_drop_animation_controller_.reset( | |
| 39 new views::InkDropAnimationController(this)); | |
| 40 layer()->SetFillsBoundsOpaquely(false); | |
|
Peter Kasting
2015/07/17 18:01:58
Why do we need this if it's unconditionally done o
bruthig
2015/07/20 14:53:07
Line 55 is operating on image() whereas this is op
| |
| 41 } | |
| 42 #endif // defined(OS_CHROMEOS) | |
| 43 | |
| 34 set_context_menu_controller(this); | 44 set_context_menu_controller(this); |
| 35 } | 45 } |
| 36 | 46 |
| 37 ToolbarButton::~ToolbarButton() { | 47 ToolbarButton::~ToolbarButton() { |
| 38 } | 48 } |
| 39 | 49 |
| 40 void ToolbarButton::Init() { | 50 void ToolbarButton::Init() { |
| 41 SetFocusable(false); | 51 SetFocusable(false); |
| 42 SetAccessibilityFocusable(true); | 52 SetAccessibilityFocusable(true); |
| 43 image()->EnableCanvasFlippingForRTLUI(true); | 53 image()->EnableCanvasFlippingForRTLUI(true); |
| 54 image()->SetPaintToLayer(true); | |
| 55 image()->SetFillsBoundsOpaquely(false); | |
| 44 } | 56 } |
| 45 | 57 |
| 46 void ToolbarButton::ClearPendingMenu() { | 58 void ToolbarButton::ClearPendingMenu() { |
| 47 show_menu_factory_.InvalidateWeakPtrs(); | 59 show_menu_factory_.InvalidateWeakPtrs(); |
| 48 } | 60 } |
| 49 | 61 |
| 50 bool ToolbarButton::IsMenuShowing() const { | 62 bool ToolbarButton::IsMenuShowing() const { |
| 51 return menu_showing_; | 63 return menu_showing_; |
| 52 } | 64 } |
| 53 | 65 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; | 153 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; |
| 142 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 154 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); |
| 143 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 155 state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 144 } | 156 } |
| 145 | 157 |
| 146 scoped_ptr<views::LabelButtonBorder> | 158 scoped_ptr<views::LabelButtonBorder> |
| 147 ToolbarButton::CreateDefaultBorder() const { | 159 ToolbarButton::CreateDefaultBorder() const { |
| 148 scoped_ptr<views::LabelButtonBorder> border = | 160 scoped_ptr<views::LabelButtonBorder> border = |
| 149 LabelButton::CreateDefaultBorder(); | 161 LabelButton::CreateDefaultBorder(); |
| 150 | 162 |
| 163 if (ui::MaterialDesignController::IsModeMaterial()) { | |
|
Peter Kasting
2015/07/17 18:01:58
I suggest adding a comment on this block as to why
bruthig
2015/07/20 14:53:07
Done.
| |
| 164 border->SetPainter(true, Button::STATE_HOVERED, nullptr); | |
| 165 border->SetPainter(false, Button::STATE_HOVERED, nullptr); | |
| 166 #if defined(OS_CHROMEOS) | |
| 167 border->SetPainter(true, Button::STATE_PRESSED, nullptr); | |
| 168 border->SetPainter(false, Button::STATE_PRESSED, nullptr); | |
| 169 #endif // defined(OS_CHROMEOS) | |
| 170 } | |
| 171 | |
| 151 ui::ThemeProvider* provider = GetThemeProvider(); | 172 ui::ThemeProvider* provider = GetThemeProvider(); |
| 152 if (provider && provider->UsingSystemTheme()) { | 173 if (provider && provider->UsingSystemTheme()) { |
| 153 // Theme provided insets. | 174 // Theme provided insets. |
| 154 int inset = provider->GetDisplayProperty( | 175 int inset = provider->GetDisplayProperty( |
| 155 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); | 176 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); |
| 156 border->set_insets(gfx::Insets(inset, inset, inset, inset)); | 177 border->set_insets(gfx::Insets(inset, inset, inset, inset)); |
| 157 } | 178 } |
| 158 | 179 |
| 159 return border.Pass(); | 180 return border.Pass(); |
| 160 } | 181 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 SetMouseHandler(NULL); | 282 SetMouseHandler(NULL); |
| 262 | 283 |
| 263 // Set the state back to normal after the drop down menu is closed. | 284 // Set the state back to normal after the drop down menu is closed. |
| 264 if (state_ != STATE_DISABLED) | 285 if (state_ != STATE_DISABLED) |
| 265 SetState(STATE_NORMAL); | 286 SetState(STATE_NORMAL); |
| 266 } | 287 } |
| 267 | 288 |
| 268 const char* ToolbarButton::GetClassName() const { | 289 const char* ToolbarButton::GetClassName() const { |
| 269 return "ToolbarButton"; | 290 return "ToolbarButton"; |
| 270 } | 291 } |
| OLD | NEW |