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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 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 // Padding between "Title:" and the actual title. |
| 41 const int kTitlePadding = 4; | 41 const int kTitlePadding = 4; |
| 42 | 42 |
| 43 // Minimum width for the fields - they will push out the size of the bubble if | 43 // Minimum width for the fields - they will push out the size of the bubble if |
|
msw
2013/06/01 02:05:53
nit: update comment.
tfarina
2013/06/01 03:33:42
Done.
| |
| 44 // necessary. This should be big enough so that the field pushes the right side | 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 | 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. | 46 // of the field's left edge. |
| 47 const int kMinimumFieldSize = 180; | 47 const int kMinBubbleWidth = 336; |
| 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 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 178 | 178 |
| 179 ColumnSet* cs = layout->AddColumnSet(0); | 179 ColumnSet* cs = layout->AddColumnSet(0); |
| 180 | 180 |
| 181 // Top (title) row. | 181 // Top (title) row. |
| 182 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 182 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
| 183 0, 0); | 183 0, 0); |
| 184 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 184 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| 185 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 185 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
| 186 0, 0); | 186 0, 0); |
| 187 | 187 |
| 188 // Middle (input field) rows. | |
| 189 cs = layout->AddColumnSet(2); | 188 cs = layout->AddColumnSet(2); |
| 190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 189 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 191 GridLayout::USE_PREF, 0, 0); | 190 GridLayout::USE_PREF, 0, 0); |
| 192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 191 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
| 193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | |
| 194 GridLayout::USE_PREF, 0, kMinimumFieldSize); | |
| 195 | 192 |
| 196 // Bottom (buttons) row. | 193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| 197 cs = layout->AddColumnSet(3); | 194 GridLayout::USE_PREF, 0, 0); |
| 198 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 195 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); |
| 196 | |
| 199 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 197 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| 200 GridLayout::USE_PREF, 0, 0); | 198 GridLayout::USE_PREF, 0, 0); |
| 201 // We subtract 2 to account for the natural button padding, and | 199 // We subtract 2 to account for the natural button padding, and |
| 202 // to bring the separation visually in line with the row separation | 200 // to bring the separation visually in line with the row separation |
| 203 // height. | 201 // height. |
| 204 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); | 202 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
| 203 | |
| 205 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 204 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| 206 GridLayout::USE_PREF, 0, 0); | 205 GridLayout::USE_PREF, 0, 0); |
| 207 | 206 |
| 208 layout->StartRow(0, 0); | 207 layout->StartRow(0, 0); |
| 209 layout->AddView(title_label); | 208 layout->AddView(title_label); |
| 210 layout->AddView(remove_link_); | |
| 211 | 209 |
| 212 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 210 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 211 | |
| 213 layout->StartRow(0, 2); | 212 layout->StartRow(0, 2); |
| 214 views::Label* label = new views::Label( | 213 views::Label* label = new views::Label( |
| 215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 214 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
| 216 layout->AddView(label); | 215 layout->AddView(label); |
| 217 title_tf_ = new views::Textfield(); | 216 title_tf_ = new views::Textfield(); |
| 218 title_tf_->SetText(GetTitle()); | 217 title_tf_->SetText(GetTitle()); |
| 219 layout->AddView(title_tf_); | 218 layout->AddView(title_tf_, 5, 1); |
| 220 | 219 |
| 221 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 220 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 222 | 221 |
| 223 layout->StartRow(0, 2); | 222 layout->StartRow(0, 2); |
| 224 layout->AddView(combobox_label); | 223 layout->AddView(combobox_label); |
| 225 layout->AddView(parent_combobox_); | 224 layout->AddView(parent_combobox_, 5, 1); |
| 225 | |
| 226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 227 | 227 |
| 228 layout->StartRow(0, 3); | 228 layout->StartRow(0, 2); |
| 229 layout->SkipColumns(2); | |
| 230 layout->AddView(remove_button_); | |
| 229 layout->AddView(edit_button_); | 231 layout->AddView(edit_button_); |
| 230 layout->AddView(close_button_); | 232 layout->AddView(close_button_); |
| 231 | 233 |
| 232 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 234 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| 233 } | 235 } |
| 234 | 236 |
| 235 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, | 237 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, |
| 236 BookmarkBubbleViewObserver* observer, | 238 BookmarkBubbleViewObserver* observer, |
| 237 Profile* profile, | 239 Profile* profile, |
| 238 const GURL& url, | 240 const GURL& url, |
| 239 bool newly_bookmarked) | 241 bool newly_bookmarked) |
| 240 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 242 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 241 observer_(observer), | 243 observer_(observer), |
| 242 profile_(profile), | 244 profile_(profile), |
| 243 url_(url), | 245 url_(url), |
| 244 newly_bookmarked_(newly_bookmarked), | 246 newly_bookmarked_(newly_bookmarked), |
| 245 parent_model_( | 247 parent_model_( |
| 246 BookmarkModelFactory::GetForProfile(profile_), | 248 BookmarkModelFactory::GetForProfile(profile_), |
| 247 BookmarkModelFactory::GetForProfile(profile_)-> | 249 BookmarkModelFactory::GetForProfile(profile_)-> |
| 248 GetMostRecentlyAddedNodeForURL(url)), | 250 GetMostRecentlyAddedNodeForURL(url)), |
| 249 remove_link_(NULL), | 251 remove_button_(NULL), |
| 250 edit_button_(NULL), | 252 edit_button_(NULL), |
| 251 close_button_(NULL), | 253 close_button_(NULL), |
| 252 title_tf_(NULL), | 254 title_tf_(NULL), |
| 253 parent_combobox_(NULL), | 255 parent_combobox_(NULL), |
| 254 remove_bookmark_(false), | 256 remove_bookmark_(false), |
| 255 apply_edits_(true) { | 257 apply_edits_(true) { |
| 256 // Compensate for built-in vertical padding in the anchor view's image. | 258 // Compensate for built-in vertical padding in the anchor view's image. |
| 257 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 259 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
| 258 } | 260 } |
| 259 | 261 |
| 260 string16 BookmarkBubbleView::GetTitle() { | 262 string16 BookmarkBubbleView::GetTitle() { |
| 261 BookmarkModel* bookmark_model = | 263 BookmarkModel* bookmark_model = |
| 262 BookmarkModelFactory::GetForProfile(profile_); | 264 BookmarkModelFactory::GetForProfile(profile_); |
| 263 const BookmarkNode* node = | 265 const BookmarkNode* node = |
| 264 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | 266 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
| 265 if (node) | 267 if (node) |
| 266 return node->GetTitle(); | 268 return node->GetTitle(); |
| 267 else | 269 else |
| 268 NOTREACHED(); | 270 NOTREACHED(); |
| 269 return string16(); | 271 return string16(); |
| 270 } | 272 } |
| 271 | 273 |
| 274 gfx::Size BookmarkBubbleView::GetMinimumSize() { | |
| 275 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); | |
| 276 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); | |
| 277 return size; | |
| 278 } | |
| 279 | |
| 272 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 280 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
| 273 const ui::Event& event) { | 281 const ui::Event& event) { |
| 274 HandleButtonPressed(sender); | 282 HandleButtonPressed(sender); |
| 275 } | 283 } |
| 276 | 284 |
| 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) { | 285 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { |
| 288 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 286 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
| 289 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 287 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
| 290 ShowEditor(); | 288 ShowEditor(); |
| 291 } | 289 } |
| 292 } | 290 } |
| 293 | 291 |
| 294 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 292 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
| 295 if (sender == edit_button_) { | 293 if (sender == remove_button_) { |
| 294 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
| 295 // Set this so we remove the bookmark after the window closes. | |
| 296 remove_bookmark_ = true; | |
| 297 apply_edits_ = false; | |
| 298 StartFade(false); | |
| 299 } else if (sender == edit_button_) { | |
| 296 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 300 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
| 297 ShowEditor(); | 301 ShowEditor(); |
| 298 } else { | 302 } else { |
| 299 DCHECK_EQ(close_button_, sender); | 303 DCHECK_EQ(close_button_, sender); |
| 300 StartFade(false); | 304 StartFade(false); |
| 301 } | 305 } |
| 302 } | 306 } |
| 303 | 307 |
| 304 void BookmarkBubbleView::ShowEditor() { | 308 void BookmarkBubbleView::ShowEditor() { |
| 305 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 309 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 326 if (node) { | 330 if (node) { |
| 327 const string16 new_title = title_tf_->text(); | 331 const string16 new_title = title_tf_->text(); |
| 328 if (new_title != node->GetTitle()) { | 332 if (new_title != node->GetTitle()) { |
| 329 model->SetTitle(node, new_title); | 333 model->SetTitle(node, new_title); |
| 330 content::RecordAction( | 334 content::RecordAction( |
| 331 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 335 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 332 } | 336 } |
| 333 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 337 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
| 334 } | 338 } |
| 335 } | 339 } |
| OLD | NEW |