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

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: Improved style 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.
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 30 matching lines...) Expand all
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 const int kTitleColumnSetID = 0;
176 ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID); 190 ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID);
191 cs->AddPaddingColumn(0, kBubblePadding);
177 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, 192 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF,
178 0, 0); 193 0, 0);
194 cs->AddPaddingColumn(0, kBubblePadding);
179 195
180 // The column layout used for middle and bottom rows. 196 // The column layout used for middle and bottom rows.
181 const int kFirstColumnSetID = 1; 197 const int kFirstColumnSetID = 1;
182 cs = layout->AddColumnSet(kFirstColumnSetID); 198 cs = layout->AddColumnSet(kFirstColumnSetID);
199 cs->AddPaddingColumn(0, kBubblePadding);
183 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 200 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
184 GridLayout::USE_PREF, 0, 0); 201 GridLayout::USE_PREF, 0, 0);
185 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 202 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
186 203
187 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 204 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
188 GridLayout::USE_PREF, 0, 0); 205 GridLayout::USE_PREF, 0, 0);
189 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); 206 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing);
190 207
191 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 208 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
192 GridLayout::USE_PREF, 0, 0); 209 GridLayout::USE_PREF, 0, 0);
193 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 210 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
194 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 211 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
195 GridLayout::USE_PREF, 0, 0); 212 GridLayout::USE_PREF, 0, 0);
213 cs->AddPaddingColumn(0, kBubblePadding - kControlBorderWidth);
196 214
197 layout->StartRow(0, kTitleColumnSetID); 215 layout->StartRow(0, kTitleColumnSetID);
198 layout->AddView(title_label); 216 layout->AddView(title_label);
199 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 217 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
200 218
201 layout->StartRow(0, kFirstColumnSetID); 219 layout->StartRow(0, kFirstColumnSetID);
202 views::Label* label = new views::Label( 220 views::Label* label = new views::Label(
203 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); 221 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT));
204 layout->AddView(label); 222 layout->AddView(label);
205 title_tf_ = new views::Textfield(); 223 title_tf_ = new views::Textfield();
206 title_tf_->SetText(GetTitle()); 224 title_tf_->SetText(GetTitle());
207 layout->AddView(title_tf_, 5, 1); 225 layout->AddView(title_tf_, 5, 1);
208 226
209 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 227 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
210 228
211 layout->StartRow(0, kFirstColumnSetID); 229 layout->StartRow(0, kFirstColumnSetID);
212 layout->AddView(combobox_label); 230 layout->AddView(combobox_label);
213 layout->AddView(parent_combobox_, 5, 1); 231 layout->AddView(parent_combobox_, 5, 1);
214 232
215 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 233 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
216 234
217 layout->StartRow(0, kFirstColumnSetID); 235 layout->StartRow(0, kFirstColumnSetID);
218 layout->SkipColumns(2); 236 layout->SkipColumns(2);
219 layout->AddView(remove_button_); 237 layout->AddView(remove_button_);
220 layout->AddView(edit_button_); 238 layout->AddView(edit_button_);
221 layout->AddView(close_button_); 239 layout->AddView(close_button_);
222 240
241 layout->AddPaddingRow(0, kBubblePadding - kControlBorderWidth);
242
243 const CommandLine* command_line = CommandLine::ForCurrentProcess();
244 if (command_line->HasSwitch(switches::kEnableBookmarkSyncPromo) &&
245 SyncPromoUI::ShouldShowSyncPromo(profile_)) {
246 // The column layout used for the sync promo.
247 const int kSyncPromoColumnSetID = 2;
Roger Tawa OOO till Jul 10th 2013/07/11 15:28:30 Would it be better to put the three constants in a
fdoray 2013/07/11 19:00:40 Done.
248 cs = layout->AddColumnSet(kSyncPromoColumnSetID);
249 cs->AddColumn(GridLayout::FILL,
250 GridLayout::FILL,
251 1,
252 GridLayout::USE_PREF,
253 0,
254 0);
255
256 Browser* browser = chrome::FindBrowserWithProfile(
257 profile_,
258 chrome::HOST_DESKTOP_TYPE_NATIVE);
259 sync_promo_view_ = new BookmarkSyncPromoView(browser);
260
261 layout->StartRow(0, kSyncPromoColumnSetID);
262 layout->AddView(sync_promo_view_);
263 }
264
223 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 265 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
224 } 266 }
225 267
226 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, 268 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
227 BookmarkBubbleViewObserver* observer, 269 BookmarkBubbleViewObserver* observer,
228 Profile* profile, 270 Profile* profile,
229 const GURL& url, 271 const GURL& url,
230 bool newly_bookmarked) 272 bool newly_bookmarked)
231 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 273 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
232 observer_(observer), 274 observer_(observer),
233 profile_(profile), 275 profile_(profile),
234 url_(url), 276 url_(url),
235 newly_bookmarked_(newly_bookmarked), 277 newly_bookmarked_(newly_bookmarked),
236 parent_model_( 278 parent_model_(
237 BookmarkModelFactory::GetForProfile(profile_), 279 BookmarkModelFactory::GetForProfile(profile_),
238 BookmarkModelFactory::GetForProfile(profile_)-> 280 BookmarkModelFactory::GetForProfile(profile_)->
239 GetMostRecentlyAddedNodeForURL(url)), 281 GetMostRecentlyAddedNodeForURL(url)),
240 remove_button_(NULL), 282 remove_button_(NULL),
241 edit_button_(NULL), 283 edit_button_(NULL),
242 close_button_(NULL), 284 close_button_(NULL),
243 title_tf_(NULL), 285 title_tf_(NULL),
244 parent_combobox_(NULL), 286 parent_combobox_(NULL),
287 sync_promo_view_(NULL),
245 remove_bookmark_(false), 288 remove_bookmark_(false),
246 apply_edits_(true) { 289 apply_edits_(true) {
247 const SkColor background_color = GetNativeTheme()->GetSystemColor( 290 const SkColor background_color = GetNativeTheme()->GetSystemColor(
248 ui::NativeTheme::kColorId_DialogBackground); 291 ui::NativeTheme::kColorId_DialogBackground);
249 set_color(background_color); 292 set_color(background_color);
250 set_background(views::Background::CreateSolidBackground(background_color)); 293 set_background(views::Background::CreateSolidBackground(background_color));
251 set_margins(gfx::Insets(12, 19, 18, 18)); 294 set_margins(gfx::Insets(kBubbleTopPadding, 0, 0, 0));
252 // Compensate for built-in vertical padding in the anchor view's image. 295 // Compensate for built-in vertical padding in the anchor view's image.
253 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); 296 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0));
254 } 297 }
255 298
256 string16 BookmarkBubbleView::GetTitle() { 299 string16 BookmarkBubbleView::GetTitle() {
257 BookmarkModel* bookmark_model = 300 BookmarkModel* bookmark_model =
258 BookmarkModelFactory::GetForProfile(profile_); 301 BookmarkModelFactory::GetForProfile(profile_);
259 const BookmarkNode* node = 302 const BookmarkNode* node =
260 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 303 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
261 if (node) 304 if (node)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (node) { 367 if (node) {
325 const string16 new_title = title_tf_->text(); 368 const string16 new_title = title_tf_->text();
326 if (new_title != node->GetTitle()) { 369 if (new_title != node->GetTitle()) {
327 model->SetTitle(node, new_title); 370 model->SetTitle(node, new_title);
328 content::RecordAction( 371 content::RecordAction(
329 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 372 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
330 } 373 }
331 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 374 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
332 } 375 }
333 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698