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

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: Rebase 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/browser.h"
18 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/sync/sync_promo_ui.h"
18 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" 21 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h"
22 #include "chrome/browser/ui/views/bookmarks/bookmark_sync_promo_view.h"
23 #include "chrome/common/chrome_switches.h"
19 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
20 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
22 #include "ui/base/keycodes/keyboard_codes.h" 27 #include "ui/base/keycodes/keyboard_codes.h"
23 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/views/bubble/bubble_frame_view.h" 30 #include "ui/views/bubble/bubble_frame_view.h"
26 #include "ui/views/controls/button/label_button.h" 31 #include "ui/views/controls/button/label_button.h"
27 #include "ui/views/controls/combobox/combobox.h" 32 #include "ui/views/controls/combobox/combobox.h"
28 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
29 #include "ui/views/controls/link.h" 34 #include "ui/views/controls/link.h"
30 #include "ui/views/controls/textfield/textfield.h" 35 #include "ui/views/controls/textfield/textfield.h"
31 #include "ui/views/layout/grid_layout.h" 36 #include "ui/views/layout/grid_layout.h"
32 #include "ui/views/layout/layout_constants.h" 37 #include "ui/views/layout/layout_constants.h"
33 #include "ui/views/widget/widget.h" 38 #include "ui/views/widget/widget.h"
34 39
35 using content::UserMetricsAction; 40 using content::UserMetricsAction;
36 using views::ColumnSet; 41 using views::ColumnSet;
37 using views::GridLayout; 42 using views::GridLayout;
38 43
39 namespace { 44 namespace {
40 45
41 // Minimum width of the the bubble. 46 // Minimum width of the the bubble.
42 const int kMinBubbleWidth = 350; 47 const int kMinBubbleWidth = 350;
43 48
49 // Top padding of the bubble.
sky 2013/07/15 18:14:10 Can we use the standard constants we have instead
fdoray 2013/07/16 17:49:58 Done for kBubblePadding. But there is no relevant
fdoray 2013/07/17 15:01:59 Done.
50 const int kBubbleTopPadding = 12;
51
52 // Horizontal and bottom padding of the bubble.
53 const int kBubblePadding = 19;
54
55 // Width of the border of a button or text field.
56 const int kControlBorderWidth = 1;
57
44 } // namespace 58 } // namespace
45 59
46 // Declared in browser_dialogs.h so callers don't have to depend on our header. 60 // Declared in browser_dialogs.h so callers don't have to depend on our header.
47 61
48 namespace chrome { 62 namespace chrome {
49 63
50 void ShowBookmarkBubbleView(views::View* anchor_view, 64 void ShowBookmarkBubbleView(views::View* anchor_view,
51 BookmarkBubbleViewObserver* observer, 65 BookmarkBubbleViewObserver* observer,
52 Profile* profile, 66 Profile* profile,
53 const GURL& url, 67 const GURL& url,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
190 enum ColumnSetID {
sky 2013/07/15 18:14:10 Chrome style is ALL_CAPS for enums.
fdoray 2013/07/16 17:49:58 Done.
191 kTitleColumnSetID,
192 kContentColumnSetID,
193 kSyncPromoColumnSetID
194 };
195
176 ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID); 196 ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID);
197 cs->AddPaddingColumn(0, kBubblePadding);
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, kBubblePadding);
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(kContentColumnSetID);
182 cs = layout->AddColumnSet(kFirstColumnSetID); 204 cs->AddPaddingColumn(0, kBubblePadding);
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, kBubblePadding - kControlBorderWidth);
196 219
197 layout->StartRow(0, kTitleColumnSetID); 220 layout->StartRow(0, kTitleColumnSetID);
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, kContentColumnSetID);
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, kContentColumnSetID);
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, kContentColumnSetID);
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(0, kBubblePadding - kControlBorderWidth);
247
248 const CommandLine* command_line = CommandLine::ForCurrentProcess();
249 if (command_line->HasSwitch(switches::kEnableBookmarkSyncPromo) &&
250 SyncPromoUI::ShouldShowSyncPromo(profile_)) {
sky 2013/07/15 18:14:10 I don't like changing the meaning of ShouldShowSyn
fdoray 2013/07/16 17:49:58 ShouldShowSyncPromo is already used to determine i
sky 2013/07/16 21:23:00 My concern still stands. Isn't SyncPromoUI a speci
Roger Tawa OOO till Jul 10th 2013/07/17 13:26:32 Initially there was only one sync promo, but over
251 // The column layout used for the sync promo.
252 cs = layout->AddColumnSet(kSyncPromoColumnSetID);
253 cs->AddColumn(GridLayout::FILL,
254 GridLayout::FILL,
255 1,
256 GridLayout::USE_PREF,
257 0,
258 0);
259
260 Browser* browser = chrome::FindBrowserWithProfile(
sky 2013/07/15 18:14:10 There is nothing that forces BookmarkBubbleView to
fdoray 2013/07/16 17:49:58 I couldn't figure out how a delegate would be usef
sky 2013/07/16 21:23:00 class BookmarkBubbleViewDelegate { public: virt
fdoray 2013/07/17 15:01:59 Done. This is true on all platforms, so I wrote a
261 profile_,
262 chrome::HOST_DESKTOP_TYPE_NATIVE);
263 sync_promo_view_ = new BookmarkSyncPromoView(browser);
264
265 layout->StartRow(0, kSyncPromoColumnSetID);
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(views::View* anchor_view,
227 BookmarkBubbleViewObserver* observer, 273 BookmarkBubbleViewObserver* observer,
228 Profile* profile, 274 Profile* profile,
229 const GURL& url, 275 const GURL& url,
230 bool newly_bookmarked) 276 bool newly_bookmarked)
231 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 277 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
232 observer_(observer), 278 observer_(observer),
233 profile_(profile), 279 profile_(profile),
234 url_(url), 280 url_(url),
235 newly_bookmarked_(newly_bookmarked), 281 newly_bookmarked_(newly_bookmarked),
236 parent_model_( 282 parent_model_(
237 BookmarkModelFactory::GetForProfile(profile_), 283 BookmarkModelFactory::GetForProfile(profile_),
238 BookmarkModelFactory::GetForProfile(profile_)-> 284 BookmarkModelFactory::GetForProfile(profile_)->
239 GetMostRecentlyAddedNodeForURL(url)), 285 GetMostRecentlyAddedNodeForURL(url)),
240 remove_button_(NULL), 286 remove_button_(NULL),
241 edit_button_(NULL), 287 edit_button_(NULL),
242 close_button_(NULL), 288 close_button_(NULL),
243 title_tf_(NULL), 289 title_tf_(NULL),
244 parent_combobox_(NULL), 290 parent_combobox_(NULL),
291 sync_promo_view_(NULL),
245 remove_bookmark_(false), 292 remove_bookmark_(false),
246 apply_edits_(true) { 293 apply_edits_(true) {
247 const SkColor background_color = GetNativeTheme()->GetSystemColor( 294 const SkColor background_color = GetNativeTheme()->GetSystemColor(
248 ui::NativeTheme::kColorId_DialogBackground); 295 ui::NativeTheme::kColorId_DialogBackground);
249 set_color(background_color); 296 set_color(background_color);
250 set_background(views::Background::CreateSolidBackground(background_color)); 297 set_background(views::Background::CreateSolidBackground(background_color));
251 set_margins(gfx::Insets(12, 19, 18, 18)); 298 set_margins(gfx::Insets(kBubbleTopPadding, 0, 0, 0));
252 // Compensate for built-in vertical padding in the anchor view's image. 299 // Compensate for built-in vertical padding in the anchor view's image.
253 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); 300 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0));
254 } 301 }
255 302
256 string16 BookmarkBubbleView::GetTitle() { 303 string16 BookmarkBubbleView::GetTitle() {
257 BookmarkModel* bookmark_model = 304 BookmarkModel* bookmark_model =
258 BookmarkModelFactory::GetForProfile(profile_); 305 BookmarkModelFactory::GetForProfile(profile_);
259 const BookmarkNode* node = 306 const BookmarkNode* node =
260 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 307 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
261 if (node) 308 if (node)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (node) { 371 if (node) {
325 const string16 new_title = title_tf_->text(); 372 const string16 new_title = title_tf_->text();
326 if (new_title != node->GetTitle()) { 373 if (new_title != node->GetTitle()) {
327 model->SetTitle(node, new_title); 374 model->SetTitle(node, new_title);
328 content::RecordAction( 375 content::RecordAction(
329 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 376 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
330 } 377 }
331 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 378 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
332 } 379 }
333 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698