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" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 204 } |
205 | 205 |
206 void AppMenuButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 206 void AppMenuButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
207 layer()->Remove(ink_drop_layer); | 207 layer()->Remove(ink_drop_layer); |
208 | 208 |
209 image()->SetFillsBoundsOpaquely(true); | 209 image()->SetFillsBoundsOpaquely(true); |
210 image()->SetPaintToLayer(false); | 210 image()->SetPaintToLayer(false); |
211 SetPaintToLayer(false); | 211 SetPaintToLayer(false); |
212 } | 212 } |
213 | 213 |
| 214 gfx::Point AppMenuButton::CalculateInkDropCenter() const { |
| 215 // ToolbarView extends the bounds of the app button to the right in maximized |
| 216 // mode. So instead of using the center point of local bounds, we use the |
| 217 // center point (adjusted for RTL layouts) of the preferred size, which |
| 218 // doesn't change in maximized mode. |
| 219 const int visible_width = GetPreferredSize().width(); |
| 220 return gfx::Point( |
| 221 (GetMirroredXWithWidthInView(0, visible_width) + visible_width) / 2, |
| 222 height() / 2); |
| 223 } |
| 224 |
214 const char* AppMenuButton::GetClassName() const { | 225 const char* AppMenuButton::GetClassName() const { |
215 return "AppMenuButton"; | 226 return "AppMenuButton"; |
216 } | 227 } |
217 | 228 |
218 scoped_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() | 229 scoped_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() |
219 const { | 230 const { |
220 scoped_ptr<views::LabelButtonBorder> border = | 231 scoped_ptr<views::LabelButtonBorder> border = |
221 MenuButton::CreateDefaultBorder(); | 232 MenuButton::CreateDefaultBorder(); |
222 | 233 |
223 // Adjust border insets to follow the margin change, | 234 // Adjust border insets to follow the margin change, |
(...skipping 28 matching lines...) Expand all Loading... |
252 | 263 |
253 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { | 264 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { |
254 return allow_extension_dragging_ ? | 265 return allow_extension_dragging_ ? |
255 BrowserActionDragData::CanDrop(data, | 266 BrowserActionDragData::CanDrop(data, |
256 toolbar_view_->browser()->profile()) : | 267 toolbar_view_->browser()->profile()) : |
257 views::View::CanDrop(data); | 268 views::View::CanDrop(data); |
258 } | 269 } |
259 | 270 |
260 void AppMenuButton::Layout() { | 271 void AppMenuButton::Layout() { |
261 MenuButton::Layout(); | 272 MenuButton::Layout(); |
262 | 273 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); |
263 // ToolbarView extends the bounds of the app button to the right in maximized | |
264 // mode. So instead of using the center point of local bounds, we use the | |
265 // center point (adjusted for RTL layouts) of preferred size which doesn't | |
266 // change in maximized mode. | |
267 const int visible_width = GetPreferredSize().width(); | |
268 ink_drop_animation_controller_->SetInkDropCenter(gfx::Point( | |
269 (GetMirroredXWithWidthInView(0, visible_width) + visible_width) / 2, | |
270 height() / 2)); | |
271 } | 274 } |
272 | 275 |
273 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { | 276 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { |
274 DCHECK(allow_extension_dragging_); | 277 DCHECK(allow_extension_dragging_); |
275 DCHECK(!weak_factory_.HasWeakPtrs()); | 278 DCHECK(!weak_factory_.HasWeakPtrs()); |
276 if (!g_open_app_immediately_for_testing) { | 279 if (!g_open_app_immediately_for_testing) { |
277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 280 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
278 FROM_HERE, | 281 FROM_HERE, |
279 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), | 282 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), |
280 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 283 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
(...skipping 21 matching lines...) Expand all Loading... |
302 views::MenuButton::OnPaint(canvas); | 305 views::MenuButton::OnPaint(canvas); |
303 if (ui::MaterialDesignController::IsModeMaterial()) | 306 if (ui::MaterialDesignController::IsModeMaterial()) |
304 return; | 307 return; |
305 // Use GetPreferredSize() to center the icon inside the visible bounds rather | 308 // Use GetPreferredSize() to center the icon inside the visible bounds rather |
306 // than the whole size() (which may refer to hit test region extended to the | 309 // than the whole size() (which may refer to hit test region extended to the |
307 // end of the toolbar in maximized mode). | 310 // end of the toolbar in maximized mode). |
308 icon_painter_->Paint(canvas, GetThemeProvider(), | 311 icon_painter_->Paint(canvas, GetThemeProvider(), |
309 gfx::Rect(GetPreferredSize()), | 312 gfx::Rect(GetPreferredSize()), |
310 AppMenuIconPainter::BEZEL_NONE); | 313 AppMenuIconPainter::BEZEL_NONE); |
311 } | 314 } |
OLD | NEW |