Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ui/views/controls/button/menu_button.cc

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix RTL support Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/button/menu_button.h" 5 #include "ui/views/controls/button/menu_button.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_view_state.h" 8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/base/dragdrop/drag_drop_types.h" 9 #include "ui/base/dragdrop/drag_drop_types.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/ui_base_switches_util.h" 12 #include "ui/base/ui_base_switches_util.h"
13 #include "ui/events/event.h" 13 #include "ui/events/event.h"
14 #include "ui/events/event_constants.h" 14 #include "ui/events/event_constants.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 #include "ui/gfx/text_constants.h" 18 #include "ui/gfx/text_constants.h"
19 #include "ui/resources/grit/ui_resources.h" 19 #include "ui/resources/grit/ui_resources.h"
20 #include "ui/strings/grit/ui_strings.h" 20 #include "ui/strings/grit/ui_strings.h"
21 #include "ui/views/animation/ink_drop_delegate.h" 21 #include "ui/views/animation/ink_drop_delegate.h"
22 #include "ui/views/controls/button/button.h" 22 #include "ui/views/controls/button/button.h"
23 #include "ui/views/controls/button/menu_button_listener.h" 23 #include "ui/views/controls/button/menu_button_listener.h"
24 #include "ui/views/controls/focusable_border.h"
24 #include "ui/views/mouse_constants.h" 25 #include "ui/views/mouse_constants.h"
25 #include "ui/views/resources/grit/views_resources.h" 26 #include "ui/views/resources/grit/views_resources.h"
27 #include "ui/views/style/platform_style.h"
26 #include "ui/views/widget/root_view.h" 28 #include "ui/views/widget/root_view.h"
27 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
28 30
29 using base::TimeTicks; 31 using base::TimeTicks;
30 using base::TimeDelta; 32 using base::TimeDelta;
31 33
32 namespace views { 34 namespace views {
33 35
34 // Default menu offset. 36 // Default menu offset.
35 static const int kDefaultMenuOffsetX = -2; 37 static const int kDefaultMenuOffsetX = -2;
(...skipping 30 matching lines...) Expand all
66 // 68 //
67 //////////////////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////////////////
68 70
69 MenuButton::MenuButton(const base::string16& text, 71 MenuButton::MenuButton(const base::string16& text,
70 MenuButtonListener* menu_button_listener, 72 MenuButtonListener* menu_button_listener,
71 bool show_menu_marker) 73 bool show_menu_marker)
72 : LabelButton(nullptr, text), 74 : LabelButton(nullptr, text),
73 menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY), 75 menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY),
74 listener_(menu_button_listener), 76 listener_(menu_button_listener),
75 show_menu_marker_(show_menu_marker), 77 show_menu_marker_(show_menu_marker),
76 menu_marker_(ui::ResourceBundle::GetSharedInstance()
77 .GetImageNamed(IDR_MENU_DROPARROW)
78 .ToImageSkia()),
79 destroyed_flag_(nullptr), 78 destroyed_flag_(nullptr),
80 pressed_lock_count_(0), 79 pressed_lock_count_(0),
81 increment_pressed_lock_called_(nullptr), 80 increment_pressed_lock_called_(nullptr),
82 should_disable_after_press_(false), 81 should_disable_after_press_(false),
83 weak_factory_(this) { 82 weak_factory_(this) {
84 SetHorizontalAlignment(gfx::ALIGN_LEFT); 83 SetHorizontalAlignment(gfx::ALIGN_LEFT);
84 SetBorder(PlatformStyle::CreateMenuButtonBorder());
85 set_background(PlatformStyle::CreateMenuButtonBackground().release());
tapted 2016/04/21 06:06:46 e.g. maybe this just needs to be conditional on `s
Elly Fong-Jones 2016/04/21 15:30:26 Done.
85 } 86 }
86 87
87 MenuButton::~MenuButton() { 88 MenuButton::~MenuButton() {
88 if (destroyed_flag_) 89 if (destroyed_flag_)
89 *destroyed_flag_ = true; 90 *destroyed_flag_ = true;
90 } 91 }
91 92
92 //////////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////////////////
93 // 94 //
94 // MenuButton - Public APIs 95 // MenuButton - Public APIs
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 192 }
192 193
193 //////////////////////////////////////////////////////////////////////////////// 194 ////////////////////////////////////////////////////////////////////////////////
194 // 195 //
195 // MenuButton - Events 196 // MenuButton - Events
196 // 197 //
197 //////////////////////////////////////////////////////////////////////////////// 198 ////////////////////////////////////////////////////////////////////////////////
198 199
199 gfx::Size MenuButton::GetPreferredSize() const { 200 gfx::Size MenuButton::GetPreferredSize() const {
200 gfx::Size prefsize = LabelButton::GetPreferredSize(); 201 gfx::Size prefsize = LabelButton::GetPreferredSize();
201 if (show_menu_marker_) { 202 if (show_menu_marker_) {
tapted 2016/04/21 06:06:46 nit: no curlies
Elly Fong-Jones 2016/04/21 15:30:26 Done.
202 prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft + 203 prefsize.Enlarge(PlatformStyle::GetMenuButtonArrowWidth(), 0);
203 kMenuMarkerPaddingRight,
204 0);
205 } 204 }
206 return prefsize; 205 return prefsize;
207 } 206 }
208 207
209 const char* MenuButton::GetClassName() const { 208 const char* MenuButton::GetClassName() const {
210 return kViewClassName; 209 return kViewClassName;
211 } 210 }
212 211
213 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) { 212 bool MenuButton::OnMousePressed(const ui::MouseEvent& event) {
214 if (request_focus_on_press()) 213 if (request_focus_on_press())
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 state->role = ui::AX_ROLE_POP_UP_BUTTON; 308 state->role = ui::AX_ROLE_POP_UP_BUTTON;
310 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); 309 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
311 state->AddStateFlag(ui::AX_STATE_HASPOPUP); 310 state->AddStateFlag(ui::AX_STATE_HASPOPUP);
312 } 311 }
313 312
314 void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) { 313 void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) {
315 gfx::Insets insets = GetInsets(); 314 gfx::Insets insets = GetInsets();
316 315
317 // Using the Views mirroring infrastructure incorrectly flips icon content. 316 // Using the Views mirroring infrastructure incorrectly flips icon content.
318 // Instead, manually mirror the position of the down arrow. 317 // Instead, manually mirror the position of the down arrow.
319 gfx::Rect arrow_bounds(width() - insets.right() - 318 gfx::Rect arrow_bounds(
320 menu_marker_->width() - kMenuMarkerPaddingRight, 319 width() - insets.right() - PlatformStyle::GetMenuButtonArrowWidth(), 0,
321 height() / 2 - menu_marker_->height() / 2, 320 PlatformStyle::GetMenuButtonArrowWidth(), height());
322 menu_marker_->width(), 321 gfx::ImageSkia marker = PlatformStyle::CreateMenuButtonArrow(enabled());
tapted 2016/04/21 06:06:46 `Create` here makes it sound more heavyweight than
Elly Fong-Jones 2016/04/21 15:30:26 I named it with "Create" in case at some point it
323 menu_marker_->height()); 322 arrow_bounds.ClampToCenteredSize(marker.size());
324 arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds)); 323 arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds));
325 canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y()); 324 canvas->DrawImageInt(marker, arrow_bounds.x(), arrow_bounds.y());
326 } 325 }
327 326
328 gfx::Rect MenuButton::GetChildAreaBounds() { 327 gfx::Rect MenuButton::GetChildAreaBounds() {
329 gfx::Size s = size(); 328 gfx::Size s = size();
330 329
331 if (show_menu_marker_) { 330 if (show_menu_marker_) {
tapted 2016/04/21 06:06:46 nit: no curlies
Elly Fong-Jones 2016/04/21 15:30:26 Done.
332 s.set_width(s.width() - menu_marker_->width() - kMenuMarkerPaddingLeft - 331 s.set_width(s.width() - PlatformStyle::GetMenuButtonArrowWidth());
333 kMenuMarkerPaddingRight);
334 } 332 }
335 333
336 return gfx::Rect(s); 334 return gfx::Rect(s);
337 } 335 }
338 336
339 bool MenuButton::IsTriggerableEvent(const ui::Event& event) { 337 bool MenuButton::IsTriggerableEvent(const ui::Event& event) {
340 if (!IsTriggerableEventType(event)) 338 if (!IsTriggerableEventType(event))
341 return false; 339 return false;
342 340
343 TimeDelta delta = TimeTicks::Now() - menu_closed_time_; 341 TimeDelta delta = TimeTicks::Now() - menu_closed_time_;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if (!GetWidget()) { 407 if (!GetWidget()) {
410 NOTREACHED(); 408 NOTREACHED();
411 return 0; 409 return 0;
412 } 410 }
413 411
414 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 412 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
415 return monitor_bounds.right() - 1; 413 return monitor_bounds.right() - 1;
416 } 414 }
417 415
418 } // namespace views 416 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698