Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/bookmarks/bookmark_editor.h" | 11 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_utils.h" | 14 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" | 18 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" |
| 19 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 22 #include "ui/base/keycodes/keyboard_codes.h" | 22 #include "ui/base/keycodes/keyboard_codes.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/views/bubble/bubble_frame_view.h" | |
| 25 #include "ui/views/controls/button/label_button.h" | 26 #include "ui/views/controls/button/label_button.h" |
| 26 #include "ui/views/controls/combobox/combobox.h" | 27 #include "ui/views/controls/combobox/combobox.h" |
| 27 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/link.h" | 29 #include "ui/views/controls/link.h" |
| 29 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
| 30 #include "ui/views/layout/grid_layout.h" | 31 #include "ui/views/layout/grid_layout.h" |
| 31 #include "ui/views/layout/layout_constants.h" | 32 #include "ui/views/layout/layout_constants.h" |
| 32 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 33 | 34 |
| 34 using content::UserMetricsAction; | 35 using content::UserMetricsAction; |
| 35 using views::ColumnSet; | 36 using views::ColumnSet; |
| 36 using views::GridLayout; | 37 using views::GridLayout; |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // Padding between "Title:" and the actual title. | 41 // Minimum width of the the bubble. |
| 41 const int kTitlePadding = 4; | 42 const int kMinBubbleWidth = 340; |
| 42 | |
| 43 // Minimum width for the fields - they will push out the size of the bubble if | |
| 44 // necessary. This should be big enough so that the field pushes the right side | |
| 45 // of the bubble far enough so that the edit button's left edge is to the right | |
| 46 // of the field's left edge. | |
| 47 const int kMinimumFieldSize = 180; | |
| 48 | 43 |
| 49 } // namespace | 44 } // namespace |
| 50 | 45 |
| 51 // Declared in browser_dialogs.h so callers don't have to depend on our header. | 46 // Declared in browser_dialogs.h so callers don't have to depend on our header. |
| 52 | 47 |
| 53 namespace chrome { | 48 namespace chrome { |
| 54 | 49 |
| 55 void ShowBookmarkBubbleView(views::View* anchor_view, | 50 void ShowBookmarkBubbleView(views::View* anchor_view, |
| 56 BookmarkBubbleViewObserver* observer, | 51 BookmarkBubbleViewObserver* observer, |
| 57 Profile* profile, | 52 Profile* profile, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 return true; | 134 return true; |
| 140 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { | 135 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { |
| 141 remove_bookmark_ = newly_bookmarked_; | 136 remove_bookmark_ = newly_bookmarked_; |
| 142 apply_edits_ = false; | 137 apply_edits_ = false; |
| 143 } | 138 } |
| 144 | 139 |
| 145 return BubbleDelegateView::AcceleratorPressed(accelerator); | 140 return BubbleDelegateView::AcceleratorPressed(accelerator); |
| 146 } | 141 } |
| 147 | 142 |
| 148 void BookmarkBubbleView::Init() { | 143 void BookmarkBubbleView::Init() { |
| 149 remove_link_ = new views::Link(l10n_util::GetStringUTF16( | 144 remove_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( |
| 150 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | 145 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); |
| 151 remove_link_->set_listener(this); | 146 remove_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 152 | 147 |
| 153 edit_button_ = new views::LabelButton( | 148 edit_button_ = new views::LabelButton( |
| 154 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 149 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); |
| 155 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 150 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 156 | 151 |
| 157 close_button_ = new views::LabelButton( | 152 close_button_ = new views::LabelButton( |
| 158 this, l10n_util::GetStringUTF16(IDS_DONE)); | 153 this, l10n_util::GetStringUTF16(IDS_DONE)); |
| 159 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 154 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 160 close_button_->SetIsDefault(true); | 155 close_button_->SetIsDefault(true); |
| 161 | 156 |
| 162 views::Label* combobox_label = new views::Label( | 157 views::Label* combobox_label = new views::Label( |
| 163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 158 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
| 164 | 159 |
| 165 parent_combobox_ = new views::Combobox(&parent_model_); | 160 parent_combobox_ = new views::Combobox(&parent_model_); |
| 166 parent_combobox_->set_listener(this); | 161 parent_combobox_->set_listener(this); |
| 167 parent_combobox_->SetAccessibleName(combobox_label->text()); | 162 parent_combobox_->SetAccessibleName(combobox_label->text()); |
| 168 | 163 |
| 169 views::Label* title_label = new views::Label( | |
| 170 l10n_util::GetStringUTF16( | |
| 171 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : | |
| 172 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); | |
| 173 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 174 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | |
| 175 | |
| 176 GridLayout* layout = new GridLayout(this); | 164 GridLayout* layout = new GridLayout(this); |
| 177 SetLayoutManager(layout); | 165 SetLayoutManager(layout); |
| 178 | 166 |
| 179 ColumnSet* cs = layout->AddColumnSet(0); | 167 // The column layout used for middle and bottom rows. |
| 180 | 168 const int kFirstColumnSetID = 0; |
| 181 // Top (title) row. | 169 ColumnSet* cs = layout->AddColumnSet(kFirstColumnSetID); |
| 182 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | |
| 183 0, 0); | |
| 184 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | |
| 185 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | |
| 186 0, 0); | |
| 187 | |
| 188 // Middle (input field) rows. | |
| 189 cs = layout->AddColumnSet(2); | |
| 190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 170 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 191 GridLayout::USE_PREF, 0, 0); | 171 GridLayout::USE_PREF, 0, 0); |
| 192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 172 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
| 193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | |
| 194 GridLayout::USE_PREF, 0, kMinimumFieldSize); | |
| 195 | 173 |
| 196 // Bottom (buttons) row. | 174 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| 197 cs = layout->AddColumnSet(3); | 175 GridLayout::USE_PREF, 0, 0); |
| 198 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 176 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); |
| 177 | |
| 199 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 178 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| 200 GridLayout::USE_PREF, 0, 0); | 179 GridLayout::USE_PREF, 0, 0); |
| 201 // We subtract 2 to account for the natural button padding, and | 180 // We subtract 2 to account for the natural button padding, and |
| 202 // to bring the separation visually in line with the row separation | 181 // to bring the separation visually in line with the row separation |
| 203 // height. | 182 // height. |
| 204 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); | 183 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
| 205 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 184 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| 206 GridLayout::USE_PREF, 0, 0); | 185 GridLayout::USE_PREF, 0, 0); |
| 207 | 186 |
| 208 layout->StartRow(0, 0); | 187 layout->StartRow(0, kFirstColumnSetID); |
| 209 layout->AddView(title_label); | |
| 210 layout->AddView(remove_link_); | |
| 211 | |
| 212 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
| 213 layout->StartRow(0, 2); | |
| 214 views::Label* label = new views::Label( | 188 views::Label* label = new views::Label( |
| 215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 189 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
| 216 layout->AddView(label); | 190 layout->AddView(label); |
| 217 title_tf_ = new views::Textfield(); | 191 title_tf_ = new views::Textfield(); |
| 218 title_tf_->SetText(GetTitle()); | 192 title_tf_->SetText(GetTitle()); |
| 219 layout->AddView(title_tf_); | 193 layout->AddView(title_tf_, 5, 1); |
| 220 | 194 |
| 221 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 195 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); |
| 222 | 196 |
| 223 layout->StartRow(0, 2); | 197 layout->StartRow(0, kFirstColumnSetID); |
| 224 layout->AddView(combobox_label); | 198 layout->AddView(combobox_label); |
| 225 layout->AddView(parent_combobox_); | 199 layout->AddView(parent_combobox_, 5, 1); |
| 226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
| 227 | 200 |
| 228 layout->StartRow(0, 3); | 201 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 202 | |
| 203 layout->StartRow(0, kFirstColumnSetID); | |
| 204 layout->SkipColumns(2); | |
| 205 layout->AddView(remove_button_); | |
| 229 layout->AddView(edit_button_); | 206 layout->AddView(edit_button_); |
| 230 layout->AddView(close_button_); | 207 layout->AddView(close_button_); |
| 231 | 208 |
| 232 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 209 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| 233 } | 210 } |
| 234 | 211 |
| 235 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, | 212 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, |
| 236 BookmarkBubbleViewObserver* observer, | 213 BookmarkBubbleViewObserver* observer, |
| 237 Profile* profile, | 214 Profile* profile, |
| 238 const GURL& url, | 215 const GURL& url, |
| 239 bool newly_bookmarked) | 216 bool newly_bookmarked) |
| 240 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 217 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 241 observer_(observer), | 218 observer_(observer), |
| 242 profile_(profile), | 219 profile_(profile), |
| 243 url_(url), | 220 url_(url), |
| 244 newly_bookmarked_(newly_bookmarked), | 221 newly_bookmarked_(newly_bookmarked), |
| 245 parent_model_( | 222 parent_model_( |
| 246 BookmarkModelFactory::GetForProfile(profile_), | 223 BookmarkModelFactory::GetForProfile(profile_), |
| 247 BookmarkModelFactory::GetForProfile(profile_)-> | 224 BookmarkModelFactory::GetForProfile(profile_)-> |
| 248 GetMostRecentlyAddedNodeForURL(url)), | 225 GetMostRecentlyAddedNodeForURL(url)), |
| 249 remove_link_(NULL), | 226 remove_button_(NULL), |
| 250 edit_button_(NULL), | 227 edit_button_(NULL), |
| 251 close_button_(NULL), | 228 close_button_(NULL), |
| 252 title_tf_(NULL), | 229 title_tf_(NULL), |
| 253 parent_combobox_(NULL), | 230 parent_combobox_(NULL), |
| 254 remove_bookmark_(false), | 231 remove_bookmark_(false), |
| 255 apply_edits_(true) { | 232 apply_edits_(true) { |
| 233 set_margins(gfx::Insets(0, | |
| 234 views::kUnrelatedControlLargeHorizontalSpacing, | |
|
msw
2013/06/04 00:57:47
Please change the left inset to 19.
| |
| 235 views::kUnrelatedControlVerticalSpacing, | |
|
msw
2013/06/04 00:57:47
Please change the bottom inset to 18.
| |
| 236 views::kUnrelatedControlLargeHorizontalSpacing)); | |
|
msw
2013/06/04 00:57:47
Please change the right inset to 18.
| |
| 256 // Compensate for built-in vertical padding in the anchor view's image. | 237 // Compensate for built-in vertical padding in the anchor view's image. |
|
msw
2013/06/04 00:57:47
Please also set_color() to the native theme dialog
| |
| 257 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 238 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
| 258 } | 239 } |
| 259 | 240 |
| 260 string16 BookmarkBubbleView::GetTitle() { | 241 string16 BookmarkBubbleView::GetTitle() { |
| 261 BookmarkModel* bookmark_model = | 242 BookmarkModel* bookmark_model = |
| 262 BookmarkModelFactory::GetForProfile(profile_); | 243 BookmarkModelFactory::GetForProfile(profile_); |
| 263 const BookmarkNode* node = | 244 const BookmarkNode* node = |
| 264 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | 245 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
| 265 if (node) | 246 if (node) |
| 266 return node->GetTitle(); | 247 return node->GetTitle(); |
| 267 else | 248 else |
| 268 NOTREACHED(); | 249 NOTREACHED(); |
| 269 return string16(); | 250 return string16(); |
| 270 } | 251 } |
| 271 | 252 |
| 253 gfx::Size BookmarkBubbleView::GetMinimumSize() { | |
| 254 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); | |
| 255 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); | |
| 256 return size; | |
| 257 } | |
| 258 | |
| 272 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 259 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
| 273 const ui::Event& event) { | 260 const ui::Event& event) { |
| 274 HandleButtonPressed(sender); | 261 HandleButtonPressed(sender); |
| 275 } | 262 } |
| 276 | 263 |
| 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) { | 264 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { |
| 288 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 265 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
| 289 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 266 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
| 290 ShowEditor(); | 267 ShowEditor(); |
| 291 } | 268 } |
| 292 } | 269 } |
| 293 | 270 |
| 294 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 271 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
| 295 if (sender == edit_button_) { | 272 if (sender == remove_button_) { |
| 273 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
| 274 // Set this so we remove the bookmark after the window closes. | |
| 275 remove_bookmark_ = true; | |
| 276 apply_edits_ = false; | |
| 277 StartFade(false); | |
| 278 } else if (sender == edit_button_) { | |
| 296 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 279 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
| 297 ShowEditor(); | 280 ShowEditor(); |
| 298 } else { | 281 } else { |
| 299 DCHECK_EQ(close_button_, sender); | 282 DCHECK_EQ(close_button_, sender); |
| 300 StartFade(false); | 283 StartFade(false); |
| 301 } | 284 } |
| 302 } | 285 } |
| 303 | 286 |
| 304 void BookmarkBubbleView::ShowEditor() { | 287 void BookmarkBubbleView::ShowEditor() { |
| 305 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 288 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 326 if (node) { | 309 if (node) { |
| 327 const string16 new_title = title_tf_->text(); | 310 const string16 new_title = title_tf_->text(); |
| 328 if (new_title != node->GetTitle()) { | 311 if (new_title != node->GetTitle()) { |
| 329 model->SetTitle(node, new_title); | 312 model->SetTitle(node, new_title); |
| 330 content::RecordAction( | 313 content::RecordAction( |
| 331 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 314 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 332 } | 315 } |
| 333 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 316 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
| 334 } | 317 } |
| 335 } | 318 } |
| 319 | |
| 320 void BookmarkBubbleView::ViewHierarchyChanged( | |
| 321 const ViewHierarchyChangedDetails& details) { | |
| 322 if (details.is_add && details.child == this) { | |
| 323 GetBubbleFrameView()->SetTitle(l10n_util::GetStringUTF16( | |
|
msw
2013/06/04 00:57:47
Please also set_paint_arrow(PAINT_TRANSPARENT);
tfarina
2013/06/08 23:33:21
What is this for? To "remove" the arrow? If yes, t
msw
2013/06/10 18:23:47
Yeah, remove the arrow with PAINT_NONE, not PAINT_
| |
| 324 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED | |
|
msw
2013/06/04 00:57:47
Update these strings to remove the colons ':'
| |
| 325 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); | |
| 326 } | |
| 327 } | |
| OLD | NEW |