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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 void AppMenuButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 193 void AppMenuButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
194 layer()->Remove(ink_drop_layer); | 194 layer()->Remove(ink_drop_layer); |
195 | 195 |
196 image()->SetFillsBoundsOpaquely(true); | 196 image()->SetFillsBoundsOpaquely(true); |
197 image()->SetPaintToLayer(false); | 197 image()->SetPaintToLayer(false); |
198 SetPaintToLayer(false); | 198 SetPaintToLayer(false); |
199 } | 199 } |
200 | 200 |
| 201 gfx::Point AppMenuButton::CalculateInkDropCenter() const { |
| 202 // ToolbarView extends the bounds of the app button to the right in maximized |
| 203 // mode. So instead of using the center point of local bounds, we use the |
| 204 // center point of preferred size which doesn't change in maximized mode. |
| 205 return gfx::Rect(GetPreferredSize()).CenterPoint(); |
| 206 } |
| 207 |
201 const char* AppMenuButton::GetClassName() const { | 208 const char* AppMenuButton::GetClassName() const { |
202 return "AppMenuButton"; | 209 return "AppMenuButton"; |
203 } | 210 } |
204 | 211 |
205 bool AppMenuButton::GetDropFormats( | 212 bool AppMenuButton::GetDropFormats( |
206 int* formats, | 213 int* formats, |
207 std::set<ui::Clipboard::FormatType>* format_types) { | 214 std::set<ui::Clipboard::FormatType>* format_types) { |
208 return allow_extension_dragging_ ? | 215 return allow_extension_dragging_ ? |
209 BrowserActionDragData::GetDropFormats(format_types) : | 216 BrowserActionDragData::GetDropFormats(format_types) : |
210 views::View::GetDropFormats(formats, format_types); | 217 views::View::GetDropFormats(formats, format_types); |
211 } | 218 } |
212 | 219 |
213 bool AppMenuButton::AreDropTypesRequired() { | 220 bool AppMenuButton::AreDropTypesRequired() { |
214 return allow_extension_dragging_ ? | 221 return allow_extension_dragging_ ? |
215 BrowserActionDragData::AreDropTypesRequired() : | 222 BrowserActionDragData::AreDropTypesRequired() : |
216 views::View::AreDropTypesRequired(); | 223 views::View::AreDropTypesRequired(); |
217 } | 224 } |
218 | 225 |
219 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { | 226 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { |
220 return allow_extension_dragging_ ? | 227 return allow_extension_dragging_ ? |
221 BrowserActionDragData::CanDrop(data, | 228 BrowserActionDragData::CanDrop(data, |
222 toolbar_view_->browser()->profile()) : | 229 toolbar_view_->browser()->profile()) : |
223 views::View::CanDrop(data); | 230 views::View::CanDrop(data); |
224 } | 231 } |
225 | 232 |
226 void AppMenuButton::Layout() { | 233 void AppMenuButton::Layout() { |
227 MenuButton::Layout(); | 234 MenuButton::Layout(); |
228 | 235 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); |
229 // ToolbarView extends the bounds of the app button to the right in maximized | |
230 // mode. So instead of using the center point of local bounds, we use the | |
231 // center point of preferred size which doesn't change in maximized mode. | |
232 ink_drop_animation_controller_->SetInkDropCenter( | |
233 gfx::Rect(GetPreferredSize()).CenterPoint()); | |
234 } | 236 } |
235 | 237 |
236 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { | 238 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { |
237 DCHECK(allow_extension_dragging_); | 239 DCHECK(allow_extension_dragging_); |
238 DCHECK(!weak_factory_.HasWeakPtrs()); | 240 DCHECK(!weak_factory_.HasWeakPtrs()); |
239 if (!g_open_app_immediately_for_testing) { | 241 if (!g_open_app_immediately_for_testing) { |
240 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 242 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
241 FROM_HERE, | 243 FROM_HERE, |
242 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), | 244 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), |
243 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 245 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
(...skipping 17 matching lines...) Expand all Loading... |
261 return ui::DragDropTypes::DRAG_MOVE; | 263 return ui::DragDropTypes::DRAG_MOVE; |
262 } | 264 } |
263 | 265 |
264 void AppMenuButton::OnPaint(gfx::Canvas* canvas) { | 266 void AppMenuButton::OnPaint(gfx::Canvas* canvas) { |
265 views::MenuButton::OnPaint(canvas); | 267 views::MenuButton::OnPaint(canvas); |
266 if (ui::MaterialDesignController::IsModeMaterial()) | 268 if (ui::MaterialDesignController::IsModeMaterial()) |
267 return; | 269 return; |
268 icon_painter_->Paint(canvas, GetThemeProvider(), gfx::Rect(size()), | 270 icon_painter_->Paint(canvas, GetThemeProvider(), gfx::Rect(size()), |
269 AppMenuIconPainter::BEZEL_NONE); | 271 AppMenuIconPainter::BEZEL_NONE); |
270 } | 272 } |
OLD | NEW |