Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: trunk/src/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc

Issue 17413014: Revert 207802 "bookmarks: Convert "Remove" link into a LabelButton." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/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"
26 #include "ui/views/controls/button/label_button.h" 25 #include "ui/views/controls/button/label_button.h"
27 #include "ui/views/controls/combobox/combobox.h" 26 #include "ui/views/controls/combobox/combobox.h"
28 #include "ui/views/controls/label.h" 27 #include "ui/views/controls/label.h"
29 #include "ui/views/controls/link.h" 28 #include "ui/views/controls/link.h"
30 #include "ui/views/controls/textfield/textfield.h" 29 #include "ui/views/controls/textfield/textfield.h"
31 #include "ui/views/layout/grid_layout.h" 30 #include "ui/views/layout/grid_layout.h"
32 #include "ui/views/layout/layout_constants.h" 31 #include "ui/views/layout/layout_constants.h"
33 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
34 33
35 using content::UserMetricsAction; 34 using content::UserMetricsAction;
36 using views::ColumnSet; 35 using views::ColumnSet;
37 using views::GridLayout; 36 using views::GridLayout;
38 37
39 namespace { 38 namespace {
40 39
41 // Minimum width of the the bubble. 40 // Padding between "Title:" and the actual title.
42 const int kMinBubbleWidth = 350; 41 const int kTitlePadding = 4;
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;
43 48
44 } // namespace 49 } // namespace
45 50
46 // 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.
47 52
48 namespace chrome { 53 namespace chrome {
49 54
50 void ShowBookmarkBubbleView(views::View* anchor_view, 55 void ShowBookmarkBubbleView(views::View* anchor_view,
51 BookmarkBubbleViewObserver* observer, 56 BookmarkBubbleViewObserver* observer,
52 Profile* profile, 57 Profile* profile,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return true; 139 return true;
135 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { 140 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) {
136 remove_bookmark_ = newly_bookmarked_; 141 remove_bookmark_ = newly_bookmarked_;
137 apply_edits_ = false; 142 apply_edits_ = false;
138 } 143 }
139 144
140 return BubbleDelegateView::AcceleratorPressed(accelerator); 145 return BubbleDelegateView::AcceleratorPressed(accelerator);
141 } 146 }
142 147
143 void BookmarkBubbleView::Init() { 148 void BookmarkBubbleView::Init() {
144 remove_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( 149 remove_link_ = new views::Link(l10n_util::GetStringUTF16(
145 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); 150 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK));
146 remove_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); 151 remove_link_->set_listener(this);
147 152
148 edit_button_ = new views::LabelButton( 153 edit_button_ = new views::LabelButton(
149 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); 154 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS));
150 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); 155 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
151 156
152 close_button_ = new views::LabelButton( 157 close_button_ = new views::LabelButton(
153 this, l10n_util::GetStringUTF16(IDS_DONE)); 158 this, l10n_util::GetStringUTF16(IDS_DONE));
154 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); 159 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
155 close_button_->SetIsDefault(true); 160 close_button_->SetIsDefault(true);
156 161
157 views::Label* combobox_label = new views::Label( 162 views::Label* combobox_label = new views::Label(
158 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); 163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT));
159 164
160 parent_combobox_ = new views::Combobox(&parent_model_); 165 parent_combobox_ = new views::Combobox(&parent_model_);
161 parent_combobox_->set_listener(this); 166 parent_combobox_->set_listener(this);
162 parent_combobox_->SetAccessibleName(combobox_label->text()); 167 parent_combobox_->SetAccessibleName(combobox_label->text());
163 168
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
164 GridLayout* layout = new GridLayout(this); 176 GridLayout* layout = new GridLayout(this);
165 SetLayoutManager(layout); 177 SetLayoutManager(layout);
166 178
167 // The column layout used for middle and bottom rows. 179 ColumnSet* cs = layout->AddColumnSet(0);
168 const int kFirstColumnSetID = 0; 180
169 ColumnSet* cs = layout->AddColumnSet(kFirstColumnSetID); 181 // Top (title) row.
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);
170 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
171 GridLayout::USE_PREF, 0, 0); 191 GridLayout::USE_PREF, 0, 0);
172 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
194 GridLayout::USE_PREF, 0, kMinimumFieldSize);
173 195
174 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 196 // Bottom (buttons) row.
175 GridLayout::USE_PREF, 0, 0); 197 cs = layout->AddColumnSet(3);
176 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); 198 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
177
178 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 199 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
179 GridLayout::USE_PREF, 0, 0); 200 GridLayout::USE_PREF, 0, 0);
180 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 201 // We subtract 2 to account for the natural button padding, and
202 // to bring the separation visually in line with the row separation
203 // height.
204 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2);
181 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 205 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
182 GridLayout::USE_PREF, 0, 0); 206 GridLayout::USE_PREF, 0, 0);
183 207
184 layout->StartRow(0, kFirstColumnSetID); 208 layout->StartRow(0, 0);
209 layout->AddView(title_label);
210 layout->AddView(remove_link_);
211
212 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
213 layout->StartRow(0, 2);
185 views::Label* label = new views::Label( 214 views::Label* label = new views::Label(
186 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); 215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT));
187 layout->AddView(label); 216 layout->AddView(label);
188 title_tf_ = new views::Textfield(); 217 title_tf_ = new views::Textfield();
189 title_tf_->SetText(GetTitle()); 218 title_tf_->SetText(GetTitle());
190 layout->AddView(title_tf_, 5, 1); 219 layout->AddView(title_tf_);
191 220
192 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 221 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
193 222
194 layout->StartRow(0, kFirstColumnSetID); 223 layout->StartRow(0, 2);
195 layout->AddView(combobox_label); 224 layout->AddView(combobox_label);
196 layout->AddView(parent_combobox_, 5, 1); 225 layout->AddView(parent_combobox_);
226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
197 227
198 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 228 layout->StartRow(0, 3);
199
200 layout->StartRow(0, kFirstColumnSetID);
201 layout->SkipColumns(2);
202 layout->AddView(remove_button_);
203 layout->AddView(edit_button_); 229 layout->AddView(edit_button_);
204 layout->AddView(close_button_); 230 layout->AddView(close_button_);
205 231
206 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 232 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
207 } 233 }
208 234
209 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, 235 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
210 BookmarkBubbleViewObserver* observer, 236 BookmarkBubbleViewObserver* observer,
211 Profile* profile, 237 Profile* profile,
212 const GURL& url, 238 const GURL& url,
213 bool newly_bookmarked) 239 bool newly_bookmarked)
214 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 240 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
215 observer_(observer), 241 observer_(observer),
216 profile_(profile), 242 profile_(profile),
217 url_(url), 243 url_(url),
218 newly_bookmarked_(newly_bookmarked), 244 newly_bookmarked_(newly_bookmarked),
219 parent_model_( 245 parent_model_(
220 BookmarkModelFactory::GetForProfile(profile_), 246 BookmarkModelFactory::GetForProfile(profile_),
221 BookmarkModelFactory::GetForProfile(profile_)-> 247 BookmarkModelFactory::GetForProfile(profile_)->
222 GetMostRecentlyAddedNodeForURL(url)), 248 GetMostRecentlyAddedNodeForURL(url)),
223 remove_button_(NULL), 249 remove_link_(NULL),
224 edit_button_(NULL), 250 edit_button_(NULL),
225 close_button_(NULL), 251 close_button_(NULL),
226 title_tf_(NULL), 252 title_tf_(NULL),
227 parent_combobox_(NULL), 253 parent_combobox_(NULL),
228 remove_bookmark_(false), 254 remove_bookmark_(false),
229 apply_edits_(true) { 255 apply_edits_(true) {
230 const SkColor background_color = GetNativeTheme()->GetSystemColor(
231 ui::NativeTheme::kColorId_DialogBackground);
232 set_color(background_color);
233 set_background(views::Background::CreateSolidBackground(background_color));
234 set_margins(gfx::Insets(0, 19, 18, 18));
235 // Compensate for built-in vertical padding in the anchor view's image. 256 // Compensate for built-in vertical padding in the anchor view's image.
236 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); 257 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
237 } 258 }
238 259
239 string16 BookmarkBubbleView::GetTitle() { 260 string16 BookmarkBubbleView::GetTitle() {
240 BookmarkModel* bookmark_model = 261 BookmarkModel* bookmark_model =
241 BookmarkModelFactory::GetForProfile(profile_); 262 BookmarkModelFactory::GetForProfile(profile_);
242 const BookmarkNode* node = 263 const BookmarkNode* node =
243 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 264 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
244 if (node) 265 if (node)
245 return node->GetTitle(); 266 return node->GetTitle();
246 else 267 else
247 NOTREACHED(); 268 NOTREACHED();
248 return string16(); 269 return string16();
249 } 270 }
250 271
251 gfx::Size BookmarkBubbleView::GetMinimumSize() {
252 gfx::Size size(views::BubbleDelegateView::GetPreferredSize());
253 size.SetToMax(gfx::Size(kMinBubbleWidth, 0));
254 return size;
255 }
256
257 void BookmarkBubbleView::ButtonPressed(views::Button* sender, 272 void BookmarkBubbleView::ButtonPressed(views::Button* sender,
258 const ui::Event& event) { 273 const ui::Event& event) {
259 HandleButtonPressed(sender); 274 HandleButtonPressed(sender);
260 } 275 }
261 276
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
262 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { 287 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) {
263 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { 288 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) {
264 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); 289 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox"));
265 ShowEditor(); 290 ShowEditor();
266 } 291 }
267 } 292 }
268 293
269 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { 294 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) {
270 if (sender == remove_button_) { 295 if (sender == edit_button_) {
271 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
272 // Set this so we remove the bookmark after the window closes.
273 remove_bookmark_ = true;
274 apply_edits_ = false;
275 StartFade(false);
276 } else if (sender == edit_button_) {
277 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 296 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
278 ShowEditor(); 297 ShowEditor();
279 } else { 298 } else {
280 DCHECK_EQ(close_button_, sender); 299 DCHECK_EQ(close_button_, sender);
281 StartFade(false); 300 StartFade(false);
282 } 301 }
283 } 302 }
284 303
285 void BookmarkBubbleView::ShowEditor() { 304 void BookmarkBubbleView::ShowEditor() {
286 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( 305 const BookmarkNode* node = BookmarkModelFactory::GetForProfile(
(...skipping 20 matching lines...) Expand all
307 if (node) { 326 if (node) {
308 const string16 new_title = title_tf_->text(); 327 const string16 new_title = title_tf_->text();
309 if (new_title != node->GetTitle()) { 328 if (new_title != node->GetTitle()) {
310 model->SetTitle(node, new_title); 329 model->SetTitle(node, new_title);
311 content::RecordAction( 330 content::RecordAction(
312 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 331 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
313 } 332 }
314 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 333 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
315 } 334 }
316 } 335 }
317
318 void BookmarkBubbleView::ViewHierarchyChanged(
319 const ViewHierarchyChangedDetails& details) {
320 if (details.is_add && details.child == this) {
321 GetBubbleFrameView()->SetTitle(l10n_util::GetStringUTF16(
322 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED
323 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK));
324 SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
325 }
326 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698