OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/views/touchui/touch_editing_menu.h" | 5 #include "ui/views/touchui/touch_editing_menu.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "grit/ui_strings.h" | 8 #include "grit/ui_strings.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const int kMenuButtonHeight = 38; | 29 const int kMenuButtonHeight = 38; |
30 const int kMenuButtonWidth = 63; | 30 const int kMenuButtonWidth = 63; |
31 const int kMenuMargin = 1; | 31 const int kMenuMargin = 1; |
32 | 32 |
33 const char* kEllipsesButtonText = "..."; | 33 const char* kEllipsesButtonText = "..."; |
34 const int kEllipsesButtonTag = -1; | 34 const int kEllipsesButtonTag = -1; |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 namespace views { | 37 namespace views { |
38 | 38 |
39 class TouchEditingMenuButtonBorder : public LabelButtonBorder { | |
40 public: | |
41 TouchEditingMenuButtonBorder(Button::ButtonStyle style, | |
42 const gfx::Insets& insets) | |
43 : LabelButtonBorder(style), | |
44 insets_(insets) { | |
45 } | |
46 | |
47 virtual ~TouchEditingMenuButtonBorder() { | |
48 } | |
49 | |
50 private: | |
51 // Overridden from LabelButtonBorder | |
52 virtual gfx::Insets GetInsets() const OVERRIDE { | |
53 return insets_; | |
54 } | |
55 | |
56 gfx::Insets insets_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(TouchEditingMenuButtonBorder); | |
59 }; | |
60 | |
61 TouchEditingMenuView::TouchEditingMenuView( | 39 TouchEditingMenuView::TouchEditingMenuView( |
62 TouchEditingMenuController* controller, | 40 TouchEditingMenuController* controller, |
63 gfx::Rect anchor_rect, | 41 gfx::Rect anchor_rect, |
64 gfx::NativeView context) | 42 gfx::NativeView context) |
65 : BubbleDelegateView(NULL, views::BubbleBorder::BOTTOM_CENTER), | 43 : BubbleDelegateView(NULL, views::BubbleBorder::BOTTOM_CENTER), |
66 controller_(controller) { | 44 controller_(controller) { |
67 set_anchor_rect(anchor_rect); | 45 set_anchor_rect(anchor_rect); |
68 set_shadow(views::BubbleBorder::SMALL_SHADOW); | 46 set_shadow(views::BubbleBorder::SMALL_SHADOW); |
69 set_parent_window(context); | 47 set_parent_window(context); |
70 set_margins(gfx::Insets(kMenuMargin, kMenuMargin, kMenuMargin, kMenuMargin)); | 48 set_margins(gfx::Insets(kMenuMargin, kMenuMargin, kMenuMargin, kMenuMargin)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 Layout(); | 125 Layout(); |
148 } | 126 } |
149 | 127 |
150 Button* TouchEditingMenuView::CreateButton(const string16& title, int tag) { | 128 Button* TouchEditingMenuView::CreateButton(const string16& title, int tag) { |
151 string16 label = gfx::RemoveAcceleratorChar(title, '&', NULL, NULL); | 129 string16 label = gfx::RemoveAcceleratorChar(title, '&', NULL, NULL); |
152 LabelButton* button = new LabelButton(this, label); | 130 LabelButton* button = new LabelButton(this, label); |
153 button->set_focusable(true); | 131 button->set_focusable(true); |
154 button->set_request_focus_on_press(false); | 132 button->set_request_focus_on_press(false); |
155 gfx::Font font = ui::ResourceBundle::GetSharedInstance().GetFont( | 133 gfx::Font font = ui::ResourceBundle::GetSharedInstance().GetFont( |
156 ui::ResourceBundle::SmallFont); | 134 ui::ResourceBundle::SmallFont); |
| 135 scoped_ptr<LabelButtonBorder> button_border( |
| 136 new LabelButtonBorder(button->style())); |
157 int v_border = (kMenuButtonHeight - font.GetHeight()) / 2; | 137 int v_border = (kMenuButtonHeight - font.GetHeight()) / 2; |
158 int h_border = (kMenuButtonWidth - font.GetStringWidth(label)) / 2; | 138 int h_border = (kMenuButtonWidth - font.GetStringWidth(label)) / 2; |
159 button->set_border(new TouchEditingMenuButtonBorder(button->style(), | 139 button_border->set_insets( |
160 gfx::Insets(v_border, h_border, v_border, h_border))); | 140 gfx::Insets(v_border, h_border, v_border, h_border)); |
| 141 button->set_border(button_border.release()); |
161 button->SetFont(font); | 142 button->SetFont(font); |
162 button->set_tag(tag); | 143 button->set_tag(tag); |
163 return button; | 144 return button; |
164 } | 145 } |
165 | 146 |
166 } // namespace views | 147 } // namespace views |
OLD | NEW |