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

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

Powered by Google App Engine
This is Rietveld 408576698