OLD | NEW |
---|---|
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 "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" |
6 | 6 |
7 #include "base/string16.h" | 7 #include "base/string16.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "ui/views/layout/grid_layout.h" | 30 #include "ui/views/layout/grid_layout.h" |
31 #include "ui/views/layout/layout_constants.h" | 31 #include "ui/views/layout/layout_constants.h" |
32 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
33 | 33 |
34 using content::UserMetricsAction; | 34 using content::UserMetricsAction; |
35 using views::ColumnSet; | 35 using views::ColumnSet; |
36 using views::GridLayout; | 36 using views::GridLayout; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Padding between "Title:" and the actual title. | 40 // Minimum size of the bubble. This is used to shrink the width of the bubble |
msw
2013/06/01 18:04:38
Actually, this minimum width is clamping the bubbl
tfarina
2013/06/01 19:43:37
Done.
| |
41 const int kTitlePadding = 4; | 41 // in order to reduce/compress the size of the textfields and thus the size |
42 // of the "Remove" button, otherwise they just look big and ugly. | |
43 const int kMinBubbleWidth = 336; | |
42 | 44 |
43 // Minimum width for the fields - they will push out the size of the bubble if | 45 // The padding used between textfield and combobox and between combobox and the |
44 // necessary. This should be big enough so that the field pushes the right side | 46 // button's row. |
45 // of the bubble far enough so that the edit button's left edge is to the right | 47 const int kVerticalSpacing = 10; |
46 // of the field's left edge. | |
47 const int kMinimumFieldSize = 180; | |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // Declared in browser_dialogs.h so callers don't have to depend on our header. | 51 // Declared in browser_dialogs.h so callers don't have to depend on our header. |
52 | 52 |
53 namespace chrome { | 53 namespace chrome { |
54 | 54 |
55 void ShowBookmarkBubbleView(views::View* anchor_view, | 55 void ShowBookmarkBubbleView(views::View* anchor_view, |
56 BookmarkBubbleViewObserver* observer, | 56 BookmarkBubbleViewObserver* observer, |
57 Profile* profile, | 57 Profile* profile, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 return true; | 139 return true; |
140 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { | 140 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { |
141 remove_bookmark_ = newly_bookmarked_; | 141 remove_bookmark_ = newly_bookmarked_; |
142 apply_edits_ = false; | 142 apply_edits_ = false; |
143 } | 143 } |
144 | 144 |
145 return BubbleDelegateView::AcceleratorPressed(accelerator); | 145 return BubbleDelegateView::AcceleratorPressed(accelerator); |
146 } | 146 } |
147 | 147 |
148 void BookmarkBubbleView::Init() { | 148 void BookmarkBubbleView::Init() { |
149 remove_link_ = new views::Link(l10n_util::GetStringUTF16( | 149 remove_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( |
150 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | 150 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); |
151 remove_link_->set_listener(this); | 151 remove_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
152 | 152 |
153 edit_button_ = new views::LabelButton( | 153 edit_button_ = new views::LabelButton( |
154 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 154 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); |
155 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 155 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
156 | 156 |
157 close_button_ = new views::LabelButton( | 157 close_button_ = new views::LabelButton( |
158 this, l10n_util::GetStringUTF16(IDS_DONE)); | 158 this, l10n_util::GetStringUTF16(IDS_DONE)); |
159 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 159 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
160 close_button_->SetIsDefault(true); | 160 close_button_->SetIsDefault(true); |
161 | 161 |
162 views::Label* combobox_label = new views::Label( | 162 views::Label* combobox_label = new views::Label( |
163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
164 | 164 |
165 parent_combobox_ = new views::Combobox(&parent_model_); | 165 parent_combobox_ = new views::Combobox(&parent_model_); |
166 parent_combobox_->set_listener(this); | 166 parent_combobox_->set_listener(this); |
167 parent_combobox_->SetAccessibleName(combobox_label->text()); | 167 parent_combobox_->SetAccessibleName(combobox_label->text()); |
168 | 168 |
169 views::Label* title_label = new views::Label( | 169 views::Label* title_label = new views::Label( |
170 l10n_util::GetStringUTF16( | 170 l10n_util::GetStringUTF16( |
171 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : | 171 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : |
172 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); | 172 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); |
173 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 173 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
174 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 174 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
175 | 175 |
176 GridLayout* layout = new GridLayout(this); | 176 GridLayout* layout = new GridLayout(this); |
177 SetLayoutManager(layout); | 177 SetLayoutManager(layout); |
178 | 178 |
179 ColumnSet* cs = layout->AddColumnSet(0); | 179 const int kFirstColumnSetID = 0; |
180 ColumnSet* cs = layout->AddColumnSet(kFirstColumnSetID); | |
180 | 181 |
181 // Top (title) row. | 182 // Top (title) row. |
msw
2013/06/01 18:04:38
Still hoping you'll use the bubble's title feature
tfarina
2013/06/01 19:43:37
Done.
| |
182 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 183 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
183 0, 0); | 184 0, 0); |
184 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 185 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
185 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 186 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
186 0, 0); | 187 0, 0); |
187 | 188 |
188 // Middle (input field) rows. | 189 // The column layout used for middle and bottom rows. |
189 cs = layout->AddColumnSet(2); | 190 const int kSecondColumnSetID = 1; |
191 cs = layout->AddColumnSet(kSecondColumnSetID); | |
190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 192 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
191 GridLayout::USE_PREF, 0, 0); | 193 GridLayout::USE_PREF, 0, 0); |
192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 194 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | |
194 GridLayout::USE_PREF, 0, kMinimumFieldSize); | |
195 | 195 |
196 // Bottom (buttons) row. | 196 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
197 cs = layout->AddColumnSet(3); | 197 GridLayout::USE_PREF, 0, 0); |
198 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 198 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); |
199 | |
199 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 200 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
200 GridLayout::USE_PREF, 0, 0); | 201 GridLayout::USE_PREF, 0, 0); |
201 // We subtract 2 to account for the natural button padding, and | 202 // We subtract 2 to account for the natural button padding, and |
202 // to bring the separation visually in line with the row separation | 203 // to bring the separation visually in line with the row separation |
203 // height. | 204 // height. |
204 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); | 205 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
205 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 206 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
206 GridLayout::USE_PREF, 0, 0); | 207 GridLayout::USE_PREF, 0, 0); |
207 | 208 |
208 layout->StartRow(0, 0); | 209 layout->StartRow(0, kFirstColumnSetID); |
209 layout->AddView(title_label); | 210 layout->AddView(title_label); |
210 layout->AddView(remove_link_); | 211 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
211 | 212 |
212 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 213 layout->StartRow(0, kSecondColumnSetID); |
213 layout->StartRow(0, 2); | |
214 views::Label* label = new views::Label( | 214 views::Label* label = new views::Label( |
215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
216 layout->AddView(label); | 216 layout->AddView(label); |
217 title_tf_ = new views::Textfield(); | 217 title_tf_ = new views::Textfield(); |
218 title_tf_->SetText(GetTitle()); | 218 title_tf_->SetText(GetTitle()); |
219 layout->AddView(title_tf_); | 219 layout->AddView(title_tf_, 5, 1); |
220 | 220 |
221 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 221 layout->AddPaddingRow(0, kVerticalSpacing); |
222 | 222 |
223 layout->StartRow(0, 2); | 223 layout->StartRow(0, kSecondColumnSetID); |
224 layout->AddView(combobox_label); | 224 layout->AddView(combobox_label); |
225 layout->AddView(parent_combobox_); | 225 layout->AddView(parent_combobox_, 5, 1); |
226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
227 | 226 |
228 layout->StartRow(0, 3); | 227 layout->AddPaddingRow(0, kVerticalSpacing); |
228 | |
229 layout->StartRow(0, kSecondColumnSetID); | |
230 layout->SkipColumns(2); | |
231 layout->AddView(remove_button_); | |
229 layout->AddView(edit_button_); | 232 layout->AddView(edit_button_); |
230 layout->AddView(close_button_); | 233 layout->AddView(close_button_); |
231 | 234 |
232 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 235 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
233 } | 236 } |
234 | 237 |
235 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, | 238 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, |
236 BookmarkBubbleViewObserver* observer, | 239 BookmarkBubbleViewObserver* observer, |
237 Profile* profile, | 240 Profile* profile, |
238 const GURL& url, | 241 const GURL& url, |
239 bool newly_bookmarked) | 242 bool newly_bookmarked) |
240 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 243 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
241 observer_(observer), | 244 observer_(observer), |
242 profile_(profile), | 245 profile_(profile), |
243 url_(url), | 246 url_(url), |
244 newly_bookmarked_(newly_bookmarked), | 247 newly_bookmarked_(newly_bookmarked), |
245 parent_model_( | 248 parent_model_( |
246 BookmarkModelFactory::GetForProfile(profile_), | 249 BookmarkModelFactory::GetForProfile(profile_), |
247 BookmarkModelFactory::GetForProfile(profile_)-> | 250 BookmarkModelFactory::GetForProfile(profile_)-> |
248 GetMostRecentlyAddedNodeForURL(url)), | 251 GetMostRecentlyAddedNodeForURL(url)), |
249 remove_link_(NULL), | 252 remove_button_(NULL), |
250 edit_button_(NULL), | 253 edit_button_(NULL), |
251 close_button_(NULL), | 254 close_button_(NULL), |
252 title_tf_(NULL), | 255 title_tf_(NULL), |
253 parent_combobox_(NULL), | 256 parent_combobox_(NULL), |
254 remove_bookmark_(false), | 257 remove_bookmark_(false), |
255 apply_edits_(true) { | 258 apply_edits_(true) { |
259 set_margins(gfx::Insets(13, | |
msw
2013/06/01 18:04:38
reduce the top inset here (probably to 0), if you'
tfarina
2013/06/01 19:43:37
Done.
| |
260 views::kUnrelatedControlLargeHorizontalSpacing, | |
261 views::kUnrelatedControlVerticalSpacing, | |
262 views::kUnrelatedControlLargeHorizontalSpacing)); | |
256 // Compensate for built-in vertical padding in the anchor view's image. | 263 // Compensate for built-in vertical padding in the anchor view's image. |
257 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 264 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
258 } | 265 } |
259 | 266 |
260 string16 BookmarkBubbleView::GetTitle() { | 267 string16 BookmarkBubbleView::GetTitle() { |
261 BookmarkModel* bookmark_model = | 268 BookmarkModel* bookmark_model = |
262 BookmarkModelFactory::GetForProfile(profile_); | 269 BookmarkModelFactory::GetForProfile(profile_); |
263 const BookmarkNode* node = | 270 const BookmarkNode* node = |
264 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | 271 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
265 if (node) | 272 if (node) |
266 return node->GetTitle(); | 273 return node->GetTitle(); |
267 else | 274 else |
268 NOTREACHED(); | 275 NOTREACHED(); |
269 return string16(); | 276 return string16(); |
270 } | 277 } |
271 | 278 |
279 gfx::Size BookmarkBubbleView::GetMinimumSize() { | |
280 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); | |
281 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); | |
282 return size; | |
283 } | |
284 | |
272 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 285 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
273 const ui::Event& event) { | 286 const ui::Event& event) { |
274 HandleButtonPressed(sender); | 287 HandleButtonPressed(sender); |
275 } | 288 } |
276 | 289 |
277 void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) { | |
278 DCHECK_EQ(remove_link_, source); | |
279 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
280 | |
281 // Set this so we remove the bookmark after the window closes. | |
282 remove_bookmark_ = true; | |
283 apply_edits_ = false; | |
284 StartFade(false); | |
285 } | |
286 | |
287 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { | 290 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { |
288 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 291 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
289 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 292 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
290 ShowEditor(); | 293 ShowEditor(); |
291 } | 294 } |
292 } | 295 } |
293 | 296 |
294 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 297 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
295 if (sender == edit_button_) { | 298 if (sender == remove_button_) { |
299 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
300 // Set this so we remove the bookmark after the window closes. | |
301 remove_bookmark_ = true; | |
302 apply_edits_ = false; | |
303 StartFade(false); | |
304 } else if (sender == edit_button_) { | |
296 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 305 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
297 ShowEditor(); | 306 ShowEditor(); |
298 } else { | 307 } else { |
299 DCHECK_EQ(close_button_, sender); | 308 DCHECK_EQ(close_button_, sender); |
300 StartFade(false); | 309 StartFade(false); |
301 } | 310 } |
302 } | 311 } |
303 | 312 |
304 void BookmarkBubbleView::ShowEditor() { | 313 void BookmarkBubbleView::ShowEditor() { |
305 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 314 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
(...skipping 20 matching lines...) Expand all Loading... | |
326 if (node) { | 335 if (node) { |
327 const string16 new_title = title_tf_->text(); | 336 const string16 new_title = title_tf_->text(); |
328 if (new_title != node->GetTitle()) { | 337 if (new_title != node->GetTitle()) { |
329 model->SetTitle(node, new_title); | 338 model->SetTitle(node, new_title); |
330 content::RecordAction( | 339 content::RecordAction( |
331 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 340 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
332 } | 341 } |
333 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 342 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
334 } | 343 } |
335 } | 344 } |
OLD | NEW |