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

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: Common layout constants 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 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,
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(views::View* anchor_view,
75 BookmarkBubbleViewObserver* observer, 85 BookmarkBubbleViewObserver* observer,
86 BookmarkBubbleDelegate* delegate,
76 Profile* profile, 87 Profile* profile,
77 const GURL& url, 88 const GURL& url,
78 bool newly_bookmarked) { 89 bool newly_bookmarked) {
79 if (IsShowing()) 90 if (IsShowing())
80 return; 91 return;
81 92
82 bookmark_bubble_ = new BookmarkBubbleView(anchor_view, observer, profile, url, 93 bookmark_bubble_ = new BookmarkBubbleView(anchor_view,
94 observer,
95 delegate,
96 profile,
97 url,
83 newly_bookmarked); 98 newly_bookmarked);
84 views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show(); 99 views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show();
85 // Select the entire title textfield contents when the bubble is first shown. 100 // Select the entire title textfield contents when the bubble is first shown.
86 bookmark_bubble_->title_tf_->SelectAll(true); 101 bookmark_bubble_->title_tf_->SelectAll(true);
87 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 102 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
88 103
89 if (bookmark_bubble_->observer_) 104 if (bookmark_bubble_->observer_)
90 bookmark_bubble_->observer_->OnBookmarkBubbleShown(url); 105 bookmark_bubble_->observer_->OnBookmarkBubbleShown(url);
91 } 106 }
92 107
(...skipping 23 matching lines...) Expand all
116 } 131 }
117 132
118 void BookmarkBubbleView::WindowClosing() { 133 void BookmarkBubbleView::WindowClosing() {
119 // We have to reset |bubble_| here, not in our destructor, because we'll be 134 // 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. 135 // destroyed asynchronously and the shown state will be checked before then.
121 DCHECK_EQ(bookmark_bubble_, this); 136 DCHECK_EQ(bookmark_bubble_, this);
122 bookmark_bubble_ = NULL; 137 bookmark_bubble_ = NULL;
123 138
124 if (observer_) 139 if (observer_)
125 observer_->OnBookmarkBubbleHidden(); 140 observer_->OnBookmarkBubbleHidden();
126 } 141 }
127 142
128 bool BookmarkBubbleView::AcceleratorPressed( 143 bool BookmarkBubbleView::AcceleratorPressed(
129 const ui::Accelerator& accelerator) { 144 const ui::Accelerator& accelerator) {
130 if (accelerator.key_code() == ui::VKEY_RETURN) { 145 if (accelerator.key_code() == ui::VKEY_RETURN) {
131 if (edit_button_->HasFocus()) 146 if (edit_button_->HasFocus())
132 HandleButtonPressed(edit_button_); 147 HandleButtonPressed(edit_button_);
133 else 148 else
134 HandleButtonPressed(close_button_); 149 HandleButtonPressed(close_button_);
135 return true; 150 return true;
136 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { 151 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) {
(...skipping 28 matching lines...) Expand all
165 views::Label* combobox_label = new views::Label( 180 views::Label* combobox_label = new views::Label(
166 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); 181 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT));
167 182
168 parent_combobox_ = new views::Combobox(&parent_model_); 183 parent_combobox_ = new views::Combobox(&parent_model_);
169 parent_combobox_->set_listener(this); 184 parent_combobox_->set_listener(this);
170 parent_combobox_->SetAccessibleName(combobox_label->text()); 185 parent_combobox_->SetAccessibleName(combobox_label->text());
171 186
172 GridLayout* layout = new GridLayout(this); 187 GridLayout* layout = new GridLayout(this);
173 SetLayoutManager(layout); 188 SetLayoutManager(layout);
174 189
175 const int kTitleColumnSetID = 0; 190 // Column sets used in the layout of the bubble.
176 ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID); 191 enum ColumnSetID {
192 TITLE_COLUMN_SET_ID,
193 CONTENT_COLUMN_SET_ID,
194 SYNC_PROMO_COLUMN_SET_ID
195 };
196
197 ColumnSet* cs = layout->AddColumnSet(TITLE_COLUMN_SET_ID);
198 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
177 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, 199 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF,
178 0, 0); 200 0, 0);
201 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
179 202
180 // The column layout used for middle and bottom rows. 203 // The column layout used for middle and bottom rows.
181 const int kFirstColumnSetID = 1; 204 cs = layout->AddColumnSet(CONTENT_COLUMN_SET_ID);
182 cs = layout->AddColumnSet(kFirstColumnSetID); 205 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
183 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 206 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
184 GridLayout::USE_PREF, 0, 0); 207 GridLayout::USE_PREF, 0, 0);
185 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 208 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
186 209
187 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 210 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
188 GridLayout::USE_PREF, 0, 0); 211 GridLayout::USE_PREF, 0, 0);
189 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); 212 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing);
190 213
191 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 214 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
192 GridLayout::USE_PREF, 0, 0); 215 GridLayout::USE_PREF, 0, 0);
193 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 216 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
194 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 217 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
195 GridLayout::USE_PREF, 0, 0); 218 GridLayout::USE_PREF, 0, 0);
219 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
196 220
197 layout->StartRow(0, kTitleColumnSetID); 221 layout->StartRow(0, TITLE_COLUMN_SET_ID);
198 layout->AddView(title_label); 222 layout->AddView(title_label);
199 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 223 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
200 224
201 layout->StartRow(0, kFirstColumnSetID); 225 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
202 views::Label* label = new views::Label( 226 views::Label* label = new views::Label(
203 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); 227 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT));
204 layout->AddView(label); 228 layout->AddView(label);
205 title_tf_ = new views::Textfield(); 229 title_tf_ = new views::Textfield();
206 title_tf_->SetText(GetTitle()); 230 title_tf_->SetText(GetTitle());
207 layout->AddView(title_tf_, 5, 1); 231 layout->AddView(title_tf_, 5, 1);
208 232
209 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing); 233 layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
210 234
211 layout->StartRow(0, kFirstColumnSetID); 235 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
212 layout->AddView(combobox_label); 236 layout->AddView(combobox_label);
213 layout->AddView(parent_combobox_, 5, 1); 237 layout->AddView(parent_combobox_, 5, 1);
214 238
215 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 239 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
216 240
217 layout->StartRow(0, kFirstColumnSetID); 241 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
218 layout->SkipColumns(2); 242 layout->SkipColumns(2);
219 layout->AddView(remove_button_); 243 layout->AddView(remove_button_);
220 layout->AddView(edit_button_); 244 layout->AddView(edit_button_);
221 layout->AddView(close_button_); 245 layout->AddView(close_button_);
222 246
247 layout->AddPaddingRow(
248 0,
249 views::kUnrelatedControlVerticalSpacing - kControlBorderWidth);
250
251 const CommandLine* command_line = CommandLine::ForCurrentProcess();
252 if (command_line->HasSwitch(switches::kEnableBookmarkSyncPromo) &&
253 SyncPromoUI::ShouldShowSyncPromo(profile_)) {
254 // The column layout used for the sync promo.
255 cs = layout->AddColumnSet(SYNC_PROMO_COLUMN_SET_ID);
256 cs->AddColumn(GridLayout::FILL,
257 GridLayout::FILL,
258 1,
259 GridLayout::USE_PREF,
260 0,
261 0);
262 layout->StartRow(0, SYNC_PROMO_COLUMN_SET_ID);
263
264 sync_promo_view_ = new BookmarkSyncPromoView(delegate_.get());
265 layout->AddView(sync_promo_view_);
266 }
267
223 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 268 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
224 } 269 }
225 270
226 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, 271 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
227 BookmarkBubbleViewObserver* observer, 272 BookmarkBubbleViewObserver* observer,
273 BookmarkBubbleDelegate* delegate,
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) {
294 delegate_.reset(delegate);
295
247 const SkColor background_color = GetNativeTheme()->GetSystemColor( 296 const SkColor background_color = GetNativeTheme()->GetSystemColor(
248 ui::NativeTheme::kColorId_DialogBackground); 297 ui::NativeTheme::kColorId_DialogBackground);
249 set_color(background_color); 298 set_color(background_color);
250 set_background(views::Background::CreateSolidBackground(background_color)); 299 set_background(views::Background::CreateSolidBackground(background_color));
251 set_margins(gfx::Insets(12, 19, 18, 18)); 300 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0));
252 // Compensate for built-in vertical padding in the anchor view's image. 301 // Compensate for built-in vertical padding in the anchor view's image.
253 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); 302 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0));
254 } 303 }
255 304
256 string16 BookmarkBubbleView::GetTitle() { 305 string16 BookmarkBubbleView::GetTitle() {
257 BookmarkModel* bookmark_model = 306 BookmarkModel* bookmark_model =
258 BookmarkModelFactory::GetForProfile(profile_); 307 BookmarkModelFactory::GetForProfile(profile_);
259 const BookmarkNode* node = 308 const BookmarkNode* node =
260 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 309 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
261 if (node) 310 if (node)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (node) { 373 if (node) {
325 const string16 new_title = title_tf_->text(); 374 const string16 new_title = title_tf_->text();
326 if (new_title != node->GetTitle()) { 375 if (new_title != node->GetTitle()) {
327 model->SetTitle(node, new_title); 376 model->SetTitle(node, new_title);
328 content::RecordAction( 377 content::RecordAction(
329 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 378 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
330 } 379 }
331 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 380 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
332 } 381 }
333 } 382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698