OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/website_settings/chooser_bubble_ui_view.h" | 5 #include "chrome/browser/ui/views/website_settings/chooser_bubble_ui_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "ui/accessibility/ax_view_state.h" | 23 #include "ui/accessibility/ax_view_state.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/paint_vector_icon.h" | 26 #include "ui/gfx/paint_vector_icon.h" |
27 #include "ui/gfx/text_constants.h" | 27 #include "ui/gfx/text_constants.h" |
28 #include "ui/gfx/vector_icons_public.h" | 28 #include "ui/gfx/vector_icons_public.h" |
29 #include "ui/views/bubble/bubble_delegate.h" | 29 #include "ui/views/bubble/bubble_delegate.h" |
30 #include "ui/views/bubble/bubble_frame_view.h" | 30 #include "ui/views/bubble/bubble_frame_view.h" |
31 #include "ui/views/controls/button/label_button.h" | 31 #include "ui/views/controls/button/label_button.h" |
32 #include "ui/views/controls/button/label_button_border.h" | 32 #include "ui/views/controls/button/label_button_border.h" |
33 #include "ui/views/controls/label.h" | |
34 #include "ui/views/controls/link.h" | |
35 #include "ui/views/controls/link_listener.h" | |
36 #include "ui/views/controls/separator.h" | |
33 #include "ui/views/controls/table/table_view.h" | 37 #include "ui/views/controls/table/table_view.h" |
34 #include "ui/views/controls/table/table_view_observer.h" | 38 #include "ui/views/controls/table/table_view_observer.h" |
35 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
36 #include "ui/views/layout/grid_layout.h" | 40 #include "ui/views/layout/grid_layout.h" |
37 | 41 |
38 namespace { | 42 namespace { |
39 | 43 |
40 // Chooser permission bubble width | 44 // Chooser permission bubble width |
41 const int kChooserPermissionBubbleWidth = 300; | 45 const int kChooserPermissionBubbleWidth = 300; |
42 | 46 |
43 // Chooser permission bubble height | 47 // Chooser permission bubble height |
44 const int kChooserPermissionBubbleHeight = 200; | 48 const int kChooserPermissionBubbleHeight = 200; |
45 | 49 |
46 // Spacing constant for outer margin. This is added to the | 50 // Spacing constant for outer margin. This is added to the |
47 // bubble margin itself to equalize the margins at 13px. | 51 // bubble margin itself to equalize the margins at 13px. |
48 const int kBubbleOuterMargin = 5; | 52 const int kBubbleOuterMargin = 5; |
49 | 53 |
50 // Spacing between major items should be 9px. | 54 // Spacing between major items should be 9px. |
51 const int kItemMajorSpacing = 9; | 55 const int kItemMajorSpacing = 9; |
52 | 56 |
57 // Spacing between two text labels. | |
58 const int kTextLabelSpacing = 3; | |
msw
2016/02/17 01:31:35
Try to use ui/views/layout/layout_constants.h here
juncai
2016/02/17 22:40:39
Done.
| |
59 | |
53 // Button border size, draws inside the spacing distance. | 60 // Button border size, draws inside the spacing distance. |
54 const int kButtonBorderSize = 2; | 61 const int kButtonBorderSize = 2; |
55 | 62 |
56 } // namespace | 63 } // namespace |
57 | 64 |
58 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | 65 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
59 return make_scoped_ptr(new ChooserBubbleUiView(browser_, this)); | 66 return make_scoped_ptr(new ChooserBubbleUiView(browser_, this)); |
60 } | 67 } |
61 | 68 |
62 class ChooserTableModel; | 69 class ChooserTableModel; |
63 | 70 |
64 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
65 // View implementation for the chooser bubble. | 72 // View implementation for the chooser bubble. |
66 class ChooserBubbleUiViewDelegate : public views::BubbleDelegateView, | 73 class ChooserBubbleUiViewDelegate : public views::BubbleDelegateView, |
67 public views::ButtonListener, | 74 public views::ButtonListener, |
75 public views::LinkListener, | |
68 public views::TableViewObserver { | 76 public views::TableViewObserver { |
69 public: | 77 public: |
70 ChooserBubbleUiViewDelegate(views::View* anchor_view, | 78 ChooserBubbleUiViewDelegate(views::View* anchor_view, |
71 views::BubbleBorder::Arrow anchor_arrow, | 79 views::BubbleBorder::Arrow anchor_arrow, |
72 ChooserBubbleUiView* owner, | 80 ChooserBubbleUiView* owner, |
73 ChooserBubbleDelegate* chooser_bubble_delegate); | 81 ChooserBubbleDelegate* chooser_bubble_delegate); |
74 ~ChooserBubbleUiViewDelegate() override; | 82 ~ChooserBubbleUiViewDelegate() override; |
75 | 83 |
76 void Close(); | 84 void Close(); |
77 | 85 |
78 // BubbleDelegateView: | 86 // views::BubbleDelegateView: |
79 bool ShouldShowWindowTitle() const override; | 87 bool ShouldShowWindowTitle() const override; |
80 base::string16 GetWindowTitle() const override; | 88 base::string16 GetWindowTitle() const override; |
81 void OnWidgetDestroying(views::Widget* widget) override; | 89 void OnWidgetDestroying(views::Widget* widget) override; |
82 | 90 |
83 // ButtonListener: | 91 // views::ButtonListener: |
84 void ButtonPressed(views::Button* button, const ui::Event& event) override; | 92 void ButtonPressed(views::Button* button, const ui::Event& event) override; |
85 | 93 |
94 // views::LinkListener: | |
95 void LinkClicked(views::Link* source, int event_flags) override; | |
96 | |
86 // views::TableViewObserver: | 97 // views::TableViewObserver: |
87 void OnSelectionChanged() override; | 98 void OnSelectionChanged() override; |
88 | 99 |
89 // Updates the anchor's arrow and view. Also repositions the bubble so it's | 100 // Updates the anchor's arrow and view. Also repositions the bubble so it's |
90 // displayed in the correct location. | 101 // displayed in the correct location. |
91 void UpdateAnchor(views::View* anchor_view, | 102 void UpdateAnchor(views::View* anchor_view, |
92 views::BubbleBorder::Arrow anchor_arrow); | 103 views::BubbleBorder::Arrow anchor_arrow); |
93 | 104 |
94 private: | 105 private: |
95 friend ChooserBubbleUiView; | 106 friend ChooserBubbleUiView; |
96 | 107 |
97 ChooserBubbleUiView* owner_; | 108 ChooserBubbleUiView* owner_; |
98 ChooserBubbleDelegate* chooser_bubble_delegate_; | 109 ChooserBubbleDelegate* chooser_bubble_delegate_; |
99 | 110 |
100 views::LabelButton* connect_button_; | 111 views::LabelButton* connect_button_; |
101 views::LabelButton* cancel_button_; | 112 views::LabelButton* cancel_button_; |
113 views::Link* get_help_link_; | |
102 views::TableView* table_view_; | 114 views::TableView* table_view_; |
103 ChooserTableModel* chooser_table_model_; | 115 ChooserTableModel* chooser_table_model_; |
104 bool button_pressed_; | 116 bool button_pressed_; |
105 | 117 |
106 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleUiViewDelegate); | 118 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleUiViewDelegate); |
107 }; | 119 }; |
108 | 120 |
109 ui::TableColumn ChooserTableColumn(int id, const std::string& title) { | 121 ui::TableColumn ChooserTableColumn(int id, const std::string& title) { |
110 ui::TableColumn column; | 122 ui::TableColumn column; |
111 column.id = id; | 123 column.id = id; |
(...skipping 27 matching lines...) Expand all Loading... | |
139 | 151 |
140 ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate( | 152 ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate( |
141 views::View* anchor_view, | 153 views::View* anchor_view, |
142 views::BubbleBorder::Arrow anchor_arrow, | 154 views::BubbleBorder::Arrow anchor_arrow, |
143 ChooserBubbleUiView* owner, | 155 ChooserBubbleUiView* owner, |
144 ChooserBubbleDelegate* chooser_bubble_delegate) | 156 ChooserBubbleDelegate* chooser_bubble_delegate) |
145 : views::BubbleDelegateView(anchor_view, anchor_arrow), | 157 : views::BubbleDelegateView(anchor_view, anchor_arrow), |
146 owner_(owner), | 158 owner_(owner), |
147 chooser_bubble_delegate_(chooser_bubble_delegate), | 159 chooser_bubble_delegate_(chooser_bubble_delegate), |
148 button_pressed_(false) { | 160 button_pressed_(false) { |
161 // ------------------------------------ | |
msw
2016/02/17 01:31:35
This looks so close to DialogClientView (content,
juncai
2016/02/17 22:40:39
I filed a bug and added a TODO here to try it in a
| |
162 // | Chooser bubble title | | |
163 // | -------------------------------- | | |
164 // | | option 0 | | | |
165 // | | option 1 | | | |
166 // | | option 2 | | | |
167 // | | | | | |
168 // | | | | | |
169 // | | | | | |
170 // | -------------------------------- | | |
171 // | [ Connect] [ Cancel ] | | |
msw
2016/02/17 01:31:35
nit: space after connect...
juncai
2016/02/17 22:40:39
Done.
| |
172 // |----------------------------------| | |
173 // | Not seeing your device? Get help | | |
msw
2016/02/17 01:31:35
Is "device" relevant terminology for every chooser
juncai
2016/02/17 22:40:39
It is relevant for the two components that use thi
msw
2016/02/17 22:58:16
Okay, perhaps this should be a DeviceChooserBubble
juncai
2016/02/19 01:51:00
Added a GetOptionDescription virtual function to C
juncai
2016/02/20 02:25:04
We may not need to generalize the chooser UI yet s
Jeffrey Yasskin
2016/02/22 19:54:14
It'd be better to ask if that's all right with Mik
msw
2016/02/22 20:13:11
Since the chooser is limited to bluetooth and usb
| |
174 // ------------------------------------ | |
175 | |
149 views::GridLayout* layout = new views::GridLayout(this); | 176 views::GridLayout* layout = new views::GridLayout(this); |
150 SetLayoutManager(layout); | 177 SetLayoutManager(layout); |
151 | 178 |
152 views::ColumnSet* column_set = layout->AddColumnSet(0); | 179 views::ColumnSet* column_set = layout->AddColumnSet(0); |
153 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 180 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
154 views::GridLayout::USE_PREF, 0, 0); | 181 views::GridLayout::USE_PREF, 0, 0); |
155 | 182 |
156 layout->StartRow(1, 0); | 183 layout->StartRow(0, 0); |
157 | 184 |
158 // Create a table view | 185 // Create a table view |
159 std::vector<ui::TableColumn> table_columns; | 186 std::vector<ui::TableColumn> table_columns; |
160 table_columns.push_back(ChooserTableColumn( | 187 table_columns.push_back(ChooserTableColumn( |
161 0, "" /* Empty string makes the column title invisible */)); | 188 0, "" /* Empty string makes the column title invisible */)); |
162 chooser_table_model_ = new ChooserTableModel(chooser_bubble_delegate_); | 189 chooser_table_model_ = new ChooserTableModel(chooser_bubble_delegate_); |
163 table_view_ = new views::TableView(chooser_table_model_, table_columns, | 190 table_view_ = new views::TableView(chooser_table_model_, table_columns, |
164 views::TEXT_ONLY, true); | 191 views::TEXT_ONLY, true); |
165 table_view_->set_select_on_remove(false); | 192 table_view_->set_select_on_remove(false); |
166 chooser_table_model_->SetObserver(table_view_); | 193 chooser_table_model_->SetObserver(table_view_); |
167 table_view_->SetObserver(this); | 194 table_view_->SetObserver(this); |
168 layout->AddView(table_view_->CreateParentIfNecessary(), 1, 1, | 195 layout->AddView(table_view_->CreateParentIfNecessary(), 1, 1, |
169 views::GridLayout::FILL, views::GridLayout::FILL, | 196 views::GridLayout::FILL, views::GridLayout::FILL, |
170 kChooserPermissionBubbleWidth, | 197 kChooserPermissionBubbleWidth, |
171 kChooserPermissionBubbleHeight); | 198 kChooserPermissionBubbleHeight); |
172 if (chooser_bubble_delegate_->NumOptions() == 0) { | 199 if (chooser_bubble_delegate_->NumOptions() == 0) |
173 table_view_->SetEnabled(false); | 200 table_view_->SetEnabled(false); |
174 } | |
175 | 201 |
176 layout->AddPaddingRow(0, kItemMajorSpacing); | 202 layout->AddPaddingRow(0, kItemMajorSpacing); |
177 | 203 |
178 views::View* button_row = new views::View(); | 204 views::View* button_row = new views::View(); |
179 views::GridLayout* button_layout = new views::GridLayout(button_row); | 205 views::GridLayout* button_layout = new views::GridLayout(button_row); |
180 views::ColumnSet* button_columns = button_layout->AddColumnSet(0); | 206 views::ColumnSet* button_columns = button_layout->AddColumnSet(0); |
181 button_row->SetLayoutManager(button_layout); | 207 button_row->SetLayoutManager(button_layout); |
182 layout->StartRow(1, 0); | 208 layout->StartRow(0, 0); |
183 layout->AddView(button_row); | 209 layout->AddView(button_row); |
184 | 210 |
185 // Lay out the Connect/Cancel buttons. | 211 // Lay out the Connect/Cancel buttons. |
186 button_columns->AddColumn(views::GridLayout::TRAILING, | 212 button_columns->AddColumn(views::GridLayout::TRAILING, |
187 views::GridLayout::FILL, 100, | 213 views::GridLayout::FILL, 100, |
188 views::GridLayout::USE_PREF, 0, 0); | 214 views::GridLayout::USE_PREF, 0, 0); |
189 button_columns->AddPaddingColumn(0, | 215 button_columns->AddPaddingColumn(0, |
190 kItemMajorSpacing - (2 * kButtonBorderSize)); | 216 kItemMajorSpacing - (2 * kButtonBorderSize)); |
191 button_columns->AddColumn(views::GridLayout::TRAILING, | 217 button_columns->AddColumn(views::GridLayout::TRAILING, |
192 views::GridLayout::FILL, 0, | 218 views::GridLayout::FILL, 0, |
193 views::GridLayout::USE_PREF, 0, 0); | 219 views::GridLayout::USE_PREF, 0, 0); |
194 button_layout->StartRow(0, 0); | 220 button_layout->StartRow(0, 0); |
195 | 221 |
196 base::string16 connect_text = | 222 base::string16 connect_text = |
197 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); | 223 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); |
198 connect_button_ = new views::LabelButton(this, connect_text); | 224 connect_button_ = new views::LabelButton(this, connect_text); |
199 connect_button_->SetStyle(views::Button::STYLE_BUTTON); | 225 connect_button_->SetStyle(views::Button::STYLE_BUTTON); |
200 // Disable the connect button at the beginning since no device selected yet. | 226 // Disable the connect button at the beginning since no device selected yet. |
201 connect_button_->SetEnabled(false); | 227 connect_button_->SetEnabled(false); |
202 button_layout->AddView(connect_button_); | 228 button_layout->AddView(connect_button_); |
203 chooser_table_model_->SetConnectButton(connect_button_); | 229 chooser_table_model_->SetConnectButton(connect_button_); |
204 | 230 |
205 base::string16 cancel_text = | 231 base::string16 cancel_text = |
206 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); | 232 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); |
207 cancel_button_ = new views::LabelButton(this, cancel_text); | 233 cancel_button_ = new views::LabelButton(this, cancel_text); |
208 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | 234 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
209 button_layout->AddView(cancel_button_); | 235 button_layout->AddView(cancel_button_); |
210 | 236 |
211 button_layout->AddPaddingRow(0, kBubbleOuterMargin); | 237 button_layout->AddPaddingRow(0, kBubbleOuterMargin); |
238 | |
239 layout->AddPaddingRow(0, kItemMajorSpacing); | |
240 | |
241 // Lay out the separator. | |
242 layout->StartRow(0, 0); | |
243 views::Separator* separator = | |
244 new views::Separator(views::Separator::HORIZONTAL); | |
245 layout->AddView(separator); | |
246 | |
247 layout->AddPaddingRow(0, kItemMajorSpacing); | |
248 | |
249 // Lay out the message label and link. | |
msw
2016/02/17 01:31:35
Putting the link right of the text isn't always co
juncai
2016/02/17 22:40:39
Done.
| |
250 views::View* message_row = new views::View(); | |
251 views::GridLayout* message_layout = new views::GridLayout(message_row); | |
252 views::ColumnSet* message_columns = message_layout->AddColumnSet(0); | |
253 message_row->SetLayoutManager(message_layout); | |
254 layout->StartRow(0, 0); | |
255 layout->AddView(message_row); | |
256 | |
257 message_columns->AddColumn(views::GridLayout::TRAILING, | |
258 views::GridLayout::FILL, 0, | |
259 views::GridLayout::USE_PREF, 0, 0); | |
260 message_columns->AddPaddingColumn(0, kTextLabelSpacing); | |
261 message_columns->AddColumn(views::GridLayout::TRAILING, | |
262 views::GridLayout::FILL, 0, | |
263 views::GridLayout::USE_PREF, 0, 0); | |
264 message_layout->StartRow(0, 0); | |
265 | |
266 views::Label* label = new views::Label( | |
267 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_NO_DEVICE_TEXT)); | |
268 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
269 message_layout->AddView(label); | |
270 | |
271 get_help_link_ = new views::Link( | |
272 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT)); | |
273 get_help_link_->SetEnabledColor(SkColorSetRGB(66, 133, 255)); | |
274 get_help_link_->SetUnderline(false); | |
275 get_help_link_->set_listener(this); | |
276 get_help_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
277 message_layout->AddView(get_help_link_); | |
212 } | 278 } |
213 | 279 |
214 ChooserBubbleUiViewDelegate::~ChooserBubbleUiViewDelegate() { | 280 ChooserBubbleUiViewDelegate::~ChooserBubbleUiViewDelegate() { |
215 RemoveAllChildViews(true); | 281 RemoveAllChildViews(true); |
216 if (owner_) | 282 if (owner_) |
217 owner_->Close(); | 283 owner_->Close(); |
218 chooser_table_model_->SetObserver(nullptr); | 284 chooser_table_model_->SetObserver(nullptr); |
219 } | 285 } |
220 | 286 |
221 void ChooserBubbleUiViewDelegate::Close() { | 287 void ChooserBubbleUiViewDelegate::Close() { |
(...skipping 27 matching lines...) Expand all Loading... | |
249 chooser_bubble_delegate_->Select(table_view_->selection_model().active()); | 315 chooser_bubble_delegate_->Select(table_view_->selection_model().active()); |
250 else | 316 else |
251 chooser_bubble_delegate_->Cancel(); | 317 chooser_bubble_delegate_->Cancel(); |
252 | 318 |
253 if (owner_) { | 319 if (owner_) { |
254 owner_->Close(); | 320 owner_->Close(); |
255 owner_ = nullptr; | 321 owner_ = nullptr; |
256 } | 322 } |
257 } | 323 } |
258 | 324 |
325 void ChooserBubbleUiViewDelegate::LinkClicked(views::Link* source, | |
326 int event_flags) { | |
327 if (source == get_help_link_) | |
328 chooser_bubble_delegate_->OpenHelpCenterURL(); | |
329 else | |
330 NOTREACHED(); | |
331 } | |
332 | |
259 void ChooserBubbleUiViewDelegate::OnSelectionChanged() { | 333 void ChooserBubbleUiViewDelegate::OnSelectionChanged() { |
260 connect_button_->SetEnabled(!table_view_->selection_model().empty()); | 334 connect_button_->SetEnabled(!table_view_->selection_model().empty()); |
261 } | 335 } |
262 | 336 |
263 void ChooserBubbleUiViewDelegate::UpdateAnchor( | 337 void ChooserBubbleUiViewDelegate::UpdateAnchor( |
264 views::View* anchor_view, | 338 views::View* anchor_view, |
265 views::BubbleBorder::Arrow anchor_arrow) { | 339 views::BubbleBorder::Arrow anchor_arrow) { |
266 if (GetAnchorView() == anchor_view && arrow() == anchor_arrow) | 340 if (GetAnchorView() == anchor_view && arrow() == anchor_arrow) |
267 return; | 341 return; |
268 | 342 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 return browser_view->exclusive_access_bubble()->GetView(); | 474 return browser_view->exclusive_access_bubble()->GetView(); |
401 | 475 |
402 return browser_view->top_container(); | 476 return browser_view->top_container(); |
403 } | 477 } |
404 | 478 |
405 views::BubbleBorder::Arrow ChooserBubbleUiView::GetAnchorArrow() { | 479 views::BubbleBorder::Arrow ChooserBubbleUiView::GetAnchorArrow() { |
406 if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) | 480 if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) |
407 return views::BubbleBorder::TOP_LEFT; | 481 return views::BubbleBorder::TOP_LEFT; |
408 return views::BubbleBorder::NONE; | 482 return views::BubbleBorder::NONE; |
409 } | 483 } |
OLD | NEW |