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" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ToolbarButton::CreateDefaultBorder() const { | 167 ToolbarButton::CreateDefaultBorder() const { |
168 scoped_ptr<views::LabelButtonBorder> border = | 168 scoped_ptr<views::LabelButtonBorder> border = |
169 views::LabelButton::CreateDefaultBorder(); | 169 views::LabelButton::CreateDefaultBorder(); |
170 | 170 |
171 if (ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme()) | 171 if (ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme()) |
172 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); | 172 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); |
173 | 173 |
174 return border; | 174 return border; |
175 } | 175 } |
176 | 176 |
| 177 void ToolbarButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 178 image()->SetPaintToLayer(true); |
| 179 image()->SetFillsBoundsOpaquely(false); |
| 180 views::LabelButton::AddInkDropLayer(ink_drop_layer); |
| 181 } |
| 182 |
| 183 void ToolbarButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 184 views::LabelButton::RemoveInkDropLayer(ink_drop_layer); |
| 185 image()->SetFillsBoundsOpaquely(true); |
| 186 image()->SetPaintToLayer(false); |
| 187 } |
| 188 |
177 void ToolbarButton::ShowContextMenuForView(View* source, | 189 void ToolbarButton::ShowContextMenuForView(View* source, |
178 const gfx::Point& point, | 190 const gfx::Point& point, |
179 ui::MenuSourceType source_type) { | 191 ui::MenuSourceType source_type) { |
180 if (!enabled()) | 192 if (!enabled()) |
181 return; | 193 return; |
182 | 194 |
183 show_menu_factory_.InvalidateWeakPtrs(); | 195 show_menu_factory_.InvalidateWeakPtrs(); |
184 ShowDropDownMenu(source_type); | 196 ShowDropDownMenu(source_type); |
185 } | 197 } |
186 | 198 |
187 void ToolbarButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { | |
188 SetPaintToLayer(true); | |
189 SetFillsBoundsOpaquely(false); | |
190 image()->SetPaintToLayer(true); | |
191 image()->SetFillsBoundsOpaquely(false); | |
192 | |
193 layer()->Add(ink_drop_layer); | |
194 layer()->StackAtBottom(ink_drop_layer); | |
195 } | |
196 | |
197 void ToolbarButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | |
198 layer()->Remove(ink_drop_layer); | |
199 | |
200 image()->SetFillsBoundsOpaquely(true); | |
201 image()->SetPaintToLayer(false); | |
202 SetPaintToLayer(false); | |
203 } | |
204 | |
205 bool ToolbarButton::ShouldEnterPushedState(const ui::Event& event) { | 199 bool ToolbarButton::ShouldEnterPushedState(const ui::Event& event) { |
206 // Enter PUSHED state on press with Left or Right mouse button or on taps. | 200 // Enter PUSHED state on press with Left or Right mouse button or on taps. |
207 // Remain in this state while the context menu is open. | 201 // Remain in this state while the context menu is open. |
208 return event.type() == ui::ET_GESTURE_TAP || | 202 return event.type() == ui::ET_GESTURE_TAP || |
209 event.type() == ui::ET_GESTURE_TAP_DOWN || | 203 event.type() == ui::ET_GESTURE_TAP_DOWN || |
210 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | | 204 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | |
211 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); | 205 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); |
212 } | 206 } |
213 | 207 |
214 bool ToolbarButton::ShouldShowMenu() { | 208 bool ToolbarButton::ShouldShowMenu() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 SetMouseHandler(nullptr); | 285 SetMouseHandler(nullptr); |
292 | 286 |
293 // Set the state back to normal after the drop down menu is closed. | 287 // Set the state back to normal after the drop down menu is closed. |
294 if (state() != STATE_DISABLED) | 288 if (state() != STATE_DISABLED) |
295 SetState(STATE_NORMAL); | 289 SetState(STATE_NORMAL); |
296 } | 290 } |
297 | 291 |
298 const char* ToolbarButton::GetClassName() const { | 292 const char* ToolbarButton::GetClassName() const { |
299 return "ToolbarButton"; | 293 return "ToolbarButton"; |
300 } | 294 } |
301 | |
302 gfx::Point ToolbarButton::CalculateInkDropCenter() const { | |
303 return GetLocalBounds().CenterPoint(); | |
304 } | |
OLD | NEW |