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

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

Issue 18603006: Bookmark sync promo for Views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BookmarkBubbleView independant from browser, layout_constants and CAPS for enum Created 7 years, 5 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
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_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/bookmarks/bookmark_utils.h" 13 #include "chrome/browser/bookmarks/bookmark_utils.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" 15 #include "chrome/browser/ui/bookmarks/bookmark_editor.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" 16 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h"
19 #include "content/public/browser/user_metrics.h" 17 #include "content/public/browser/user_metrics.h"
20 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
22 #include "ui/base/keycodes/keyboard_codes.h" 20 #include "ui/base/keycodes/keyboard_codes.h"
23 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/views/bubble/bubble_frame_view.h" 23 #include "ui/views/bubble/bubble_frame_view.h"
26 #include "ui/views/controls/button/label_button.h" 24 #include "ui/views/controls/button/label_button.h"
27 #include "ui/views/controls/combobox/combobox.h" 25 #include "ui/views/controls/combobox/combobox.h"
28 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
29 #include "ui/views/controls/link.h" 27 #include "ui/views/controls/link.h"
30 #include "ui/views/controls/textfield/textfield.h" 28 #include "ui/views/controls/textfield/textfield.h"
31 #include "ui/views/layout/grid_layout.h" 29 #include "ui/views/layout/grid_layout.h"
32 #include "ui/views/layout/layout_constants.h" 30 #include "ui/views/layout/layout_constants.h"
33 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
34 32
35 using content::UserMetricsAction; 33 using content::UserMetricsAction;
36 using views::ColumnSet; 34 using views::ColumnSet;
37 using views::GridLayout; 35 using views::GridLayout;
38 36
39 namespace { 37 namespace {
40 38
41 // Minimum width of the the bubble. 39 // Minimum width of the the bubble.
42 const int kMinBubbleWidth = 350; 40 const int kMinBubbleWidth = 350;
43 41
42 // Top padding of the bubble.
43 const int kBubbleTopPadding = 12;
44
45 // Width of the border of a button.
46 const int kControlBorderWidth = 2;
47
44 } // namespace 48 } // namespace
45 49
46 // Declared in browser_dialogs.h so callers don't have to depend on our header. 50 // Declared in browser_dialogs.h so callers don't have to depend on our header.
47 51
48 namespace chrome { 52 namespace chrome {
49 53
50 void ShowBookmarkBubbleView(views::View* anchor_view, 54 void ShowBookmarkBubbleView(views::View* anchor_view,
51 BookmarkBubbleViewObserver* observer, 55 BookmarkBubbleViewObserver* observer,
52 Profile* profile, 56 Profile* profile,
53 const GURL& url, 57 const GURL& url,
54 bool newly_bookmarked) { 58 bool newly_bookmarked,
55 BookmarkBubbleView::ShowBubble(anchor_view, observer, profile, url, 59 views::View* sync_promo_view) {
56 newly_bookmarked); 60 BookmarkBubbleView::ShowBubble(anchor_view,
61 observer,
62 profile,
63 url,
64 newly_bookmarked,
65 sync_promo_view);
57 } 66 }
58 67
59 void HideBookmarkBubbleView() { 68 void HideBookmarkBubbleView() {
60 BookmarkBubbleView::Hide(); 69 BookmarkBubbleView::Hide();
61 } 70 }
62 71
63 bool IsBookmarkBubbleViewShowing() { 72 bool IsBookmarkBubbleViewShowing() {
64 return BookmarkBubbleView::IsShowing(); 73 return BookmarkBubbleView::IsShowing();
65 } 74 }
66 75
67 } // namespace chrome 76 } // namespace chrome
68 77
69 // BookmarkBubbleView --------------------------------------------------------- 78 // BookmarkBubbleView ---------------------------------------------------------
70 79
71 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; 80 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL;
72 81
73 // static 82 // static
74 void BookmarkBubbleView::ShowBubble(views::View* anchor_view, 83 void BookmarkBubbleView::ShowBubble(views::View* anchor_view,
75 BookmarkBubbleViewObserver* observer, 84 BookmarkBubbleViewObserver* observer,
76 Profile* profile, 85 Profile* profile,
77 const GURL& url, 86 const GURL& url,
78 bool newly_bookmarked) { 87 bool newly_bookmarked,
88 views::View* sync_promo_view) {
79 if (IsShowing()) 89 if (IsShowing())
80 return; 90 return;
81 91
82 bookmark_bubble_ = new BookmarkBubbleView(anchor_view, observer, profile, url, 92 bookmark_bubble_ = new BookmarkBubbleView(anchor_view,
83 newly_bookmarked); 93 observer,
94 profile,
95 url,
96 newly_bookmarked,
97 sync_promo_view);
84 views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show(); 98 views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show();
85 // Select the entire title textfield contents when the bubble is first shown. 99 // Select the entire title textfield contents when the bubble is first shown.
86 bookmark_bubble_->title_tf_->SelectAll(true); 100 bookmark_bubble_->title_tf_->SelectAll(true);
87 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 101 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
88 102
89 if (bookmark_bubble_->observer_) 103 if (bookmark_bubble_->observer_)
90 bookmark_bubble_->observer_->OnBookmarkBubbleShown(url); 104 bookmark_bubble_->observer_->OnBookmarkBubbleShown(url);
91 } 105 }
92 106
93 // static 107 // static
(...skipping 22 matching lines...) Expand all
116 } 130 }
117 131
118 void BookmarkBubbleView::WindowClosing() { 132 void BookmarkBubbleView::WindowClosing() {
119 // We have to reset |bubble_| here, not in our destructor, because we'll be 133 // We have to reset |bubble_| here, not in our destructor, because we'll be
120 // destroyed asynchronously and the shown state will be checked before then. 134 // destroyed asynchronously and the shown state will be checked before then.
121 DCHECK_EQ(bookmark_bubble_, this); 135 DCHECK_EQ(bookmark_bubble_, this);
122 bookmark_bubble_ = NULL; 136 bookmark_bubble_ = NULL;
123 137
124 if (observer_) 138 if (observer_)
125 observer_->OnBookmarkBubbleHidden(); 139 observer_->OnBookmarkBubbleHidden();
126 } 140 }
127 141
128 bool BookmarkBubbleView::AcceleratorPressed( 142 bool BookmarkBubbleView::AcceleratorPressed(
129 const ui::Accelerator& accelerator) { 143 const ui::Accelerator& accelerator) {
130 if (accelerator.key_code() == ui::VKEY_RETURN) { 144 if (accelerator.key_code() == ui::VKEY_RETURN) {
131 if (edit_button_->HasFocus()) 145 if (edit_button_->HasFocus())
132 HandleButtonPressed(edit_button_); 146 HandleButtonPressed(edit_button_);
133 else 147 else
134 HandleButtonPressed(close_button_); 148 HandleButtonPressed(close_button_);
135 return true; 149 return true;
136 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { 150 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) {
(...skipping 28 matching lines...) Expand all
165 views::Label* combobox_label = new views::Label( 179 views::Label* combobox_label = new views::Label(
166 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); 180 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT));
167 181
168 parent_combobox_ = new views::Combobox(&parent_model_); 182 parent_combobox_ = new views::Combobox(&parent_model_);
169 parent_combobox_->set_listener(this); 183 parent_combobox_->set_listener(this);
170 parent_combobox_->SetAccessibleName(combobox_label->text()); 184 parent_combobox_->SetAccessibleName(combobox_label->text());
171 185
172 GridLayout* layout = new GridLayout(this); 186 GridLayout* layout = new GridLayout(this);
173 SetLayoutManager(layout); 187 SetLayoutManager(layout);
174 188
175 const int kTitleColumnSetID = 0; 189 // Column sets used in the layout of the bubble.
176 ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID); 190 enum ColumnSetID {
191 TITLE_COLUMN_SET_ID,
192 CONTENT_COLUMN_SET_ID,
193 SYNC_PROMO_COLUMN_SET_ID
194 };
195
196 ColumnSet* cs = layout->AddColumnSet(TITLE_COLUMN_SET_ID);
197 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
177 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, 198 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF,
178 0, 0); 199 0, 0);
200 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
179 201
180 // The column layout used for middle and bottom rows. 202 // The column layout used for middle and bottom rows.
181 const int kFirstColumnSetID = 1; 203 cs = layout->AddColumnSet(CONTENT_COLUMN_SET_ID);
182 cs = layout->AddColumnSet(kFirstColumnSetID); 204 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
183 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 205 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
184 GridLayout::USE_PREF, 0, 0); 206 GridLayout::USE_PREF, 0, 0);
185 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 207 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
186 208
187 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 209 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
188 GridLayout::USE_PREF, 0, 0); 210 GridLayout::USE_PREF, 0, 0);
189 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); 211 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing);
190 212
191 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 213 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
192 GridLayout::USE_PREF, 0, 0); 214 GridLayout::USE_PREF, 0, 0);
193 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 215 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
194 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 216 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
195 GridLayout::USE_PREF, 0, 0); 217 GridLayout::USE_PREF, 0, 0);
218 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
196 219
197 layout->StartRow(0, kTitleColumnSetID); 220 layout->StartRow(0, TITLE_COLUMN_SET_ID);
198 layout->AddView(title_label); 221 layout->AddView(title_label);
199 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 222 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
200 223
201 layout->StartRow(0, kFirstColumnSetID); 224 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
202 views::Label* label = new views::Label( 225 views::Label* label = new views::Label(
203 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); 226 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT));
204 layout->AddView(label); 227 layout->AddView(label);
205 title_tf_ = new views::Textfield(); 228 title_tf_ = new views::Textfield();
206 title_tf_->SetText(GetTitle()); 229 title_tf_->SetText(GetTitle());
207 layout->AddView(title_tf_, 5, 1); 230 layout->AddView(title_tf_, 5, 1);
208 231
209 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 232 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
210 233
211 layout->StartRow(0, kFirstColumnSetID); 234 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
212 layout->AddView(combobox_label); 235 layout->AddView(combobox_label);
213 layout->AddView(parent_combobox_, 5, 1); 236 layout->AddView(parent_combobox_, 5, 1);
214 237
215 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 238 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
216 239
217 layout->StartRow(0, kFirstColumnSetID); 240 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
218 layout->SkipColumns(2); 241 layout->SkipColumns(2);
219 layout->AddView(remove_button_); 242 layout->AddView(remove_button_);
220 layout->AddView(edit_button_); 243 layout->AddView(edit_button_);
221 layout->AddView(close_button_); 244 layout->AddView(close_button_);
222 245
246 layout->AddPaddingRow(
247 0,
248 views::kUnrelatedControlVerticalSpacing - kControlBorderWidth);
249
250 if (sync_promo_view_) {
251 // The column layout used for the sync promo.
252 cs = layout->AddColumnSet(SYNC_PROMO_COLUMN_SET_ID);
253 cs->AddColumn(GridLayout::FILL,
254 GridLayout::FILL,
255 1,
256 GridLayout::USE_PREF,
257 0,
258 0);
259 layout->StartRow(0, SYNC_PROMO_COLUMN_SET_ID);
260 layout->AddView(sync_promo_view_);
261 }
262
223 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 263 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
224 } 264 }
225 265
226 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, 266 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
227 BookmarkBubbleViewObserver* observer, 267 BookmarkBubbleViewObserver* observer,
228 Profile* profile, 268 Profile* profile,
229 const GURL& url, 269 const GURL& url,
230 bool newly_bookmarked) 270 bool newly_bookmarked,
271 views::View* sync_promo_view)
231 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 272 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
232 observer_(observer), 273 observer_(observer),
233 profile_(profile), 274 profile_(profile),
234 url_(url), 275 url_(url),
235 newly_bookmarked_(newly_bookmarked), 276 newly_bookmarked_(newly_bookmarked),
236 parent_model_( 277 parent_model_(
237 BookmarkModelFactory::GetForProfile(profile_), 278 BookmarkModelFactory::GetForProfile(profile_),
238 BookmarkModelFactory::GetForProfile(profile_)-> 279 BookmarkModelFactory::GetForProfile(profile_)->
239 GetMostRecentlyAddedNodeForURL(url)), 280 GetMostRecentlyAddedNodeForURL(url)),
240 remove_button_(NULL), 281 remove_button_(NULL),
241 edit_button_(NULL), 282 edit_button_(NULL),
242 close_button_(NULL), 283 close_button_(NULL),
243 title_tf_(NULL), 284 title_tf_(NULL),
244 parent_combobox_(NULL), 285 parent_combobox_(NULL),
286 sync_promo_view_(sync_promo_view),
245 remove_bookmark_(false), 287 remove_bookmark_(false),
246 apply_edits_(true) { 288 apply_edits_(true) {
247 const SkColor background_color = GetNativeTheme()->GetSystemColor( 289 const SkColor background_color = GetNativeTheme()->GetSystemColor(
248 ui::NativeTheme::kColorId_DialogBackground); 290 ui::NativeTheme::kColorId_DialogBackground);
249 set_color(background_color); 291 set_color(background_color);
250 set_background(views::Background::CreateSolidBackground(background_color)); 292 set_background(views::Background::CreateSolidBackground(background_color));
251 set_margins(gfx::Insets(12, 19, 18, 18)); 293 set_margins(gfx::Insets(kBubbleTopPadding, 0, 0, 0));
252 // Compensate for built-in vertical padding in the anchor view's image. 294 // Compensate for built-in vertical padding in the anchor view's image.
253 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); 295 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0));
254 } 296 }
255 297
256 string16 BookmarkBubbleView::GetTitle() { 298 string16 BookmarkBubbleView::GetTitle() {
257 BookmarkModel* bookmark_model = 299 BookmarkModel* bookmark_model =
258 BookmarkModelFactory::GetForProfile(profile_); 300 BookmarkModelFactory::GetForProfile(profile_);
259 const BookmarkNode* node = 301 const BookmarkNode* node =
260 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 302 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
261 if (node) 303 if (node)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (node) { 366 if (node) {
325 const string16 new_title = title_tf_->text(); 367 const string16 new_title = title_tf_->text();
326 if (new_title != node->GetTitle()) { 368 if (new_title != node->GetTitle()) {
327 model->SetTitle(node, new_title); 369 model->SetTitle(node, new_title);
328 content::RecordAction( 370 content::RecordAction(
329 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 371 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
330 } 372 }
331 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 373 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
332 } 374 }
333 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698