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/separator.h" | |
34 #include "ui/views/controls/styled_label.h" | |
35 #include "ui/views/controls/styled_label_listener.h" | |
33 #include "ui/views/controls/table/table_view.h" | 36 #include "ui/views/controls/table/table_view.h" |
34 #include "ui/views/controls/table/table_view_observer.h" | 37 #include "ui/views/controls/table/table_view_observer.h" |
35 #include "ui/views/layout/box_layout.h" | 38 #include "ui/views/layout/box_layout.h" |
36 #include "ui/views/layout/grid_layout.h" | 39 #include "ui/views/layout/grid_layout.h" |
40 #include "ui/views/layout/layout_constants.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 | |
47 // bubble margin itself to equalize the margins at 13px. | |
48 const int kBubbleOuterMargin = 5; | |
49 | |
50 // Spacing between major items should be 9px. | |
51 const int kItemMajorSpacing = 9; | |
52 | |
53 // Button border size, draws inside the spacing distance. | |
54 const int kButtonBorderSize = 2; | |
55 | |
56 } // namespace | 50 } // namespace |
57 | 51 |
58 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | 52 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
59 return make_scoped_ptr(new ChooserBubbleUiView(browser_, this)); | 53 return make_scoped_ptr(new ChooserBubbleUiView(browser_, this)); |
60 } | 54 } |
61 | 55 |
62 class ChooserTableModel; | 56 class ChooserTableModel; |
63 | 57 |
64 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
65 // View implementation for the chooser bubble. | 59 // View implementation for the chooser bubble. |
66 class ChooserBubbleUiViewDelegate : public views::BubbleDelegateView, | 60 class ChooserBubbleUiViewDelegate : public views::BubbleDelegateView, |
67 public views::ButtonListener, | 61 public views::ButtonListener, |
62 public views::StyledLabelListener, | |
68 public views::TableViewObserver { | 63 public views::TableViewObserver { |
69 public: | 64 public: |
70 ChooserBubbleUiViewDelegate(views::View* anchor_view, | 65 ChooserBubbleUiViewDelegate(views::View* anchor_view, |
71 views::BubbleBorder::Arrow anchor_arrow, | 66 views::BubbleBorder::Arrow anchor_arrow, |
72 ChooserBubbleUiView* owner, | 67 ChooserBubbleUiView* owner, |
73 ChooserBubbleDelegate* chooser_bubble_delegate); | 68 ChooserBubbleDelegate* chooser_bubble_delegate); |
74 ~ChooserBubbleUiViewDelegate() override; | 69 ~ChooserBubbleUiViewDelegate() override; |
75 | 70 |
76 void Close(); | 71 void Close(); |
77 | 72 |
78 // BubbleDelegateView: | 73 // views::BubbleDelegateView: |
79 bool ShouldShowWindowTitle() const override; | 74 bool ShouldShowWindowTitle() const override; |
80 base::string16 GetWindowTitle() const override; | 75 base::string16 GetWindowTitle() const override; |
81 void OnWidgetDestroying(views::Widget* widget) override; | 76 void OnWidgetDestroying(views::Widget* widget) override; |
82 | 77 |
83 // ButtonListener: | 78 // views::ButtonListener: |
84 void ButtonPressed(views::Button* button, const ui::Event& event) override; | 79 void ButtonPressed(views::Button* button, const ui::Event& event) override; |
85 | 80 |
81 // views::StyledLabelListener: | |
82 void StyledLabelLinkClicked(views::StyledLabel* label, | |
83 const gfx::Range& range, | |
84 int event_flags) override; | |
85 | |
86 // views::TableViewObserver: | 86 // views::TableViewObserver: |
87 void OnSelectionChanged() override; | 87 void OnSelectionChanged() override; |
88 | 88 |
89 // Updates the anchor's arrow and view. Also repositions the bubble so it's | 89 // Updates the anchor's arrow and view. Also repositions the bubble so it's |
90 // displayed in the correct location. | 90 // displayed in the correct location. |
91 void UpdateAnchor(views::View* anchor_view, | 91 void UpdateAnchor(views::View* anchor_view, |
92 views::BubbleBorder::Arrow anchor_arrow); | 92 views::BubbleBorder::Arrow anchor_arrow); |
93 | 93 |
94 private: | 94 private: |
95 friend ChooserBubbleUiView; | 95 friend ChooserBubbleUiView; |
96 | 96 |
97 ChooserBubbleUiView* owner_; | 97 ChooserBubbleUiView* owner_; |
98 ChooserBubbleDelegate* chooser_bubble_delegate_; | 98 ChooserBubbleDelegate* chooser_bubble_delegate_; |
99 | 99 |
100 views::LabelButton* connect_button_; | 100 views::LabelButton* connect_button_; |
101 views::LabelButton* cancel_button_; | 101 views::LabelButton* cancel_button_; |
102 views::StyledLabel* label_; | |
102 views::TableView* table_view_; | 103 views::TableView* table_view_; |
103 ChooserTableModel* chooser_table_model_; | 104 ChooserTableModel* chooser_table_model_; |
104 bool button_pressed_; | 105 bool button_pressed_; |
105 | 106 |
106 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleUiViewDelegate); | 107 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleUiViewDelegate); |
107 }; | 108 }; |
108 | 109 |
109 ui::TableColumn ChooserTableColumn(int id, const std::string& title) { | 110 ui::TableColumn ChooserTableColumn(int id, const std::string& title) { |
110 ui::TableColumn column; | 111 ui::TableColumn column; |
111 column.id = id; | 112 column.id = id; |
(...skipping 27 matching lines...) Expand all Loading... | |
139 | 140 |
140 ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate( | 141 ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate( |
141 views::View* anchor_view, | 142 views::View* anchor_view, |
142 views::BubbleBorder::Arrow anchor_arrow, | 143 views::BubbleBorder::Arrow anchor_arrow, |
143 ChooserBubbleUiView* owner, | 144 ChooserBubbleUiView* owner, |
144 ChooserBubbleDelegate* chooser_bubble_delegate) | 145 ChooserBubbleDelegate* chooser_bubble_delegate) |
145 : views::BubbleDelegateView(anchor_view, anchor_arrow), | 146 : views::BubbleDelegateView(anchor_view, anchor_arrow), |
146 owner_(owner), | 147 owner_(owner), |
147 chooser_bubble_delegate_(chooser_bubble_delegate), | 148 chooser_bubble_delegate_(chooser_bubble_delegate), |
148 button_pressed_(false) { | 149 button_pressed_(false) { |
150 // TODO(juncai): try using DialogClientView to build the chooser UI view since | |
151 // they look similar. | |
152 // https://crbug.com/587545 | |
153 // ------------------------------------ | |
154 // | Chooser bubble title | | |
155 // | -------------------------------- | | |
156 // | | option 0 | | | |
157 // | | option 1 | | | |
158 // | | option 2 | | | |
159 // | | | | | |
160 // | | | | | |
161 // | | | | | |
162 // | -------------------------------- | | |
163 // | [ Connect ] [ Cancel ] | | |
164 // |----------------------------------| | |
165 // | Not seeing your device? Get help | | |
166 // ------------------------------------ | |
167 | |
149 views::GridLayout* layout = new views::GridLayout(this); | 168 views::GridLayout* layout = new views::GridLayout(this); |
150 SetLayoutManager(layout); | 169 SetLayoutManager(layout); |
151 | 170 |
152 views::ColumnSet* column_set = layout->AddColumnSet(0); | 171 views::ColumnSet* column_set = layout->AddColumnSet(0); |
153 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 172 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
154 views::GridLayout::USE_PREF, 0, 0); | 173 views::GridLayout::USE_PREF, 0, 0); |
Evan Stade
2016/02/17 23:09:01
so |layout| only has one column set with one colum
juncai
2016/02/19 01:51:00
Tried using the following code to add a TableView
| |
155 | 174 |
156 layout->StartRow(1, 0); | 175 layout->StartRow(0, 0); |
msw
2016/02/17 22:58:16
Should the table's row be resizable? (if the bubbl
Jeffrey Yasskin
2016/02/17 23:54:25
The UX folks are still figuring out how to size th
| |
157 | 176 |
158 // Create a table view | 177 // Create a table view |
159 std::vector<ui::TableColumn> table_columns; | 178 std::vector<ui::TableColumn> table_columns; |
160 table_columns.push_back(ChooserTableColumn( | 179 table_columns.push_back(ChooserTableColumn( |
161 0, "" /* Empty string makes the column title invisible */)); | 180 0, "" /* Empty string makes the column title invisible */)); |
162 chooser_table_model_ = new ChooserTableModel(chooser_bubble_delegate_); | 181 chooser_table_model_ = new ChooserTableModel(chooser_bubble_delegate_); |
163 table_view_ = new views::TableView(chooser_table_model_, table_columns, | 182 table_view_ = new views::TableView(chooser_table_model_, table_columns, |
164 views::TEXT_ONLY, true); | 183 views::TEXT_ONLY, true); |
165 table_view_->set_select_on_remove(false); | 184 table_view_->set_select_on_remove(false); |
166 chooser_table_model_->SetObserver(table_view_); | 185 chooser_table_model_->SetObserver(table_view_); |
167 table_view_->SetObserver(this); | 186 table_view_->SetObserver(this); |
168 layout->AddView(table_view_->CreateParentIfNecessary(), 1, 1, | 187 layout->AddView(table_view_->CreateParentIfNecessary(), 1, 1, |
169 views::GridLayout::FILL, views::GridLayout::FILL, | 188 views::GridLayout::FILL, views::GridLayout::FILL, |
170 kChooserPermissionBubbleWidth, | 189 kChooserPermissionBubbleWidth, |
171 kChooserPermissionBubbleHeight); | 190 kChooserPermissionBubbleHeight); |
172 if (chooser_bubble_delegate_->NumOptions() == 0) { | 191 if (chooser_bubble_delegate_->NumOptions() == 0) |
173 table_view_->SetEnabled(false); | 192 table_view_->SetEnabled(false); |
174 } | |
175 | 193 |
176 layout->AddPaddingRow(0, kItemMajorSpacing); | 194 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
177 | 195 |
178 views::View* button_row = new views::View(); | 196 views::View* button_row = new views::View(); |
179 views::GridLayout* button_layout = new views::GridLayout(button_row); | 197 views::GridLayout* button_layout = new views::GridLayout(button_row); |
180 views::ColumnSet* button_columns = button_layout->AddColumnSet(0); | 198 views::ColumnSet* button_columns = button_layout->AddColumnSet(0); |
181 button_row->SetLayoutManager(button_layout); | 199 button_row->SetLayoutManager(button_layout); |
182 layout->StartRow(1, 0); | 200 layout->StartRow(0, 0); |
183 layout->AddView(button_row); | 201 layout->AddView(button_row); |
184 | 202 |
185 // Lay out the Connect/Cancel buttons. | 203 // Lay out the Connect/Cancel buttons. |
186 button_columns->AddColumn(views::GridLayout::TRAILING, | 204 button_columns->AddColumn(views::GridLayout::TRAILING, |
Evan Stade
2016/02/17 23:09:01
this also seems like it should be a (horizontal) b
juncai
2016/02/19 01:51:00
Done.
| |
187 views::GridLayout::FILL, 100, | 205 views::GridLayout::FILL, 100, |
188 views::GridLayout::USE_PREF, 0, 0); | 206 views::GridLayout::USE_PREF, 0, 0); |
189 button_columns->AddPaddingColumn(0, | 207 button_columns->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
190 kItemMajorSpacing - (2 * kButtonBorderSize)); | |
191 button_columns->AddColumn(views::GridLayout::TRAILING, | 208 button_columns->AddColumn(views::GridLayout::TRAILING, |
192 views::GridLayout::FILL, 0, | 209 views::GridLayout::FILL, 0, |
193 views::GridLayout::USE_PREF, 0, 0); | 210 views::GridLayout::USE_PREF, 0, 0); |
194 button_layout->StartRow(0, 0); | 211 button_layout->StartRow(0, 0); |
195 | 212 |
196 base::string16 connect_text = | 213 base::string16 connect_text = |
197 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); | 214 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); |
198 connect_button_ = new views::LabelButton(this, connect_text); | 215 connect_button_ = new views::LabelButton(this, connect_text); |
199 connect_button_->SetStyle(views::Button::STYLE_BUTTON); | 216 connect_button_->SetStyle(views::Button::STYLE_BUTTON); |
200 // Disable the connect button at the beginning since no device selected yet. | 217 // Disable the connect button at the beginning since no device selected yet. |
201 connect_button_->SetEnabled(false); | 218 connect_button_->SetEnabled(false); |
202 button_layout->AddView(connect_button_); | 219 button_layout->AddView(connect_button_); |
203 chooser_table_model_->SetConnectButton(connect_button_); | 220 chooser_table_model_->SetConnectButton(connect_button_); |
204 | 221 |
205 base::string16 cancel_text = | 222 base::string16 cancel_text = |
206 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); | 223 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); |
207 cancel_button_ = new views::LabelButton(this, cancel_text); | 224 cancel_button_ = new views::LabelButton(this, cancel_text); |
208 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | 225 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
209 button_layout->AddView(cancel_button_); | 226 button_layout->AddView(cancel_button_); |
210 | 227 |
211 button_layout->AddPaddingRow(0, kBubbleOuterMargin); | 228 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
229 | |
230 // Lay out the separator. | |
231 layout->StartRow(0, 0); | |
232 views::Separator* separator = | |
233 new views::Separator(views::Separator::HORIZONTAL); | |
msw
2016/02/17 22:58:16
nit: inline in AddView() call below; remove |separ
juncai
2016/02/19 01:51:00
Done.
| |
234 layout->AddView(separator); | |
235 | |
236 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
237 | |
238 // Lay out the styled label. | |
239 layout->StartRow(0, 0); | |
240 base::string16 link = | |
241 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT); | |
242 size_t offset; | |
243 base::string16 text = l10n_util::GetStringFUTF16( | |
244 IDS_CHOOSER_BUBBLE_NO_DEVICE_TEXT, link, &offset); | |
245 label_ = new views::StyledLabel(text, this); | |
246 views::StyledLabel::RangeStyleInfo link_style = | |
247 views::StyledLabel::RangeStyleInfo::CreateForLink(); | |
248 link_style.color = | |
249 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); | |
msw
2016/02/17 22:58:16
aside: odd that CreateForLink doesn't do this.
Evan Stade
2016/02/17 23:09:01
I don't think you can call GetNativeTheme() yet (a
Jeffrey Yasskin
2016/02/17 23:54:25
It does, by causing the created label at https://c
juncai
2016/02/19 01:51:00
override
views::BubbleDelegateView::OnNativeThemeC
juncai
2016/02/19 01:51:00
If I remove this line, the link still looks like a
juncai
2016/02/20 02:25:05
ok, this line of code is not needed, estade@ point
| |
250 label_->AddStyleRange(gfx::Range(offset, offset + link.length()), link_style); | |
251 layout->AddView(label_); | |
212 } | 252 } |
213 | 253 |
214 ChooserBubbleUiViewDelegate::~ChooserBubbleUiViewDelegate() { | 254 ChooserBubbleUiViewDelegate::~ChooserBubbleUiViewDelegate() { |
215 RemoveAllChildViews(true); | 255 RemoveAllChildViews(true); |
216 if (owner_) | 256 if (owner_) |
217 owner_->Close(); | 257 owner_->Close(); |
218 chooser_table_model_->SetObserver(nullptr); | 258 chooser_table_model_->SetObserver(nullptr); |
219 } | 259 } |
220 | 260 |
221 void ChooserBubbleUiViewDelegate::Close() { | 261 void ChooserBubbleUiViewDelegate::Close() { |
(...skipping 27 matching lines...) Expand all Loading... | |
249 chooser_bubble_delegate_->Select(table_view_->selection_model().active()); | 289 chooser_bubble_delegate_->Select(table_view_->selection_model().active()); |
250 else | 290 else |
251 chooser_bubble_delegate_->Cancel(); | 291 chooser_bubble_delegate_->Cancel(); |
252 | 292 |
253 if (owner_) { | 293 if (owner_) { |
254 owner_->Close(); | 294 owner_->Close(); |
255 owner_ = nullptr; | 295 owner_ = nullptr; |
256 } | 296 } |
257 } | 297 } |
258 | 298 |
299 void ChooserBubbleUiViewDelegate::StyledLabelLinkClicked( | |
300 views::StyledLabel* label, | |
301 const gfx::Range& range, | |
302 int event_flags) { | |
303 chooser_bubble_delegate_->OpenHelpCenterURL(); | |
304 } | |
305 | |
259 void ChooserBubbleUiViewDelegate::OnSelectionChanged() { | 306 void ChooserBubbleUiViewDelegate::OnSelectionChanged() { |
260 connect_button_->SetEnabled(!table_view_->selection_model().empty()); | 307 connect_button_->SetEnabled(!table_view_->selection_model().empty()); |
261 } | 308 } |
262 | 309 |
263 void ChooserBubbleUiViewDelegate::UpdateAnchor( | 310 void ChooserBubbleUiViewDelegate::UpdateAnchor( |
264 views::View* anchor_view, | 311 views::View* anchor_view, |
265 views::BubbleBorder::Arrow anchor_arrow) { | 312 views::BubbleBorder::Arrow anchor_arrow) { |
266 if (GetAnchorView() == anchor_view && arrow() == anchor_arrow) | 313 if (GetAnchorView() == anchor_view && arrow() == anchor_arrow) |
267 return; | 314 return; |
268 | 315 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 return browser_view->exclusive_access_bubble()->GetView(); | 447 return browser_view->exclusive_access_bubble()->GetView(); |
401 | 448 |
402 return browser_view->top_container(); | 449 return browser_view->top_container(); |
403 } | 450 } |
404 | 451 |
405 views::BubbleBorder::Arrow ChooserBubbleUiView::GetAnchorArrow() { | 452 views::BubbleBorder::Arrow ChooserBubbleUiView::GetAnchorArrow() { |
406 if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) | 453 if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) |
407 return views::BubbleBorder::TOP_LEFT; | 454 return views::BubbleBorder::TOP_LEFT; |
408 return views::BubbleBorder::NONE; | 455 return views::BubbleBorder::NONE; |
409 } | 456 } |
OLD | NEW |