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

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

Issue 2781553003: Integrate Desktop iOS promotion with bookmarks. (Closed)
Patch Set: integrate to bookmarks Created 3 years, 8 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 <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 21 matching lines...) Expand all
32 #include "ui/views/bubble/bubble_frame_view.h" 32 #include "ui/views/bubble/bubble_frame_view.h"
33 #include "ui/views/controls/button/md_text_button.h" 33 #include "ui/views/controls/button/md_text_button.h"
34 #include "ui/views/controls/combobox/combobox.h" 34 #include "ui/views/controls/combobox/combobox.h"
35 #include "ui/views/controls/label.h" 35 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/link.h" 36 #include "ui/views/controls/link.h"
37 #include "ui/views/controls/textfield/textfield.h" 37 #include "ui/views/controls/textfield/textfield.h"
38 #include "ui/views/layout/grid_layout.h" 38 #include "ui/views/layout/grid_layout.h"
39 #include "ui/views/layout/layout_constants.h" 39 #include "ui/views/layout/layout_constants.h"
40 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
41 41
42 #if defined(OS_WIN)
43 #include "chrome/browser/sync/profile_sync_service_factory.h"
44 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h"
45 #include "components/browser_sync/profile_sync_service.h"
46 #include "ui/views/layout/fill_layout.h"
47 #endif
48
42 using base::UserMetricsAction; 49 using base::UserMetricsAction;
43 using bookmarks::BookmarkModel; 50 using bookmarks::BookmarkModel;
44 using bookmarks::BookmarkNode; 51 using bookmarks::BookmarkNode;
45 using views::ColumnSet; 52 using views::ColumnSet;
46 using views::GridLayout; 53 using views::GridLayout;
47 54
48 namespace { 55 namespace {
49 56
50 // This combobox prevents any lengthy content from stretching the bubble view. 57 // This combobox prevents any lengthy content from stretching the bubble view.
51 class UnsizedCombobox : public views::Combobox { 58 class UnsizedCombobox : public views::Combobox {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 118
112 BookmarkBubbleView::~BookmarkBubbleView() { 119 BookmarkBubbleView::~BookmarkBubbleView() {
113 if (apply_edits_) { 120 if (apply_edits_) {
114 ApplyEdits(); 121 ApplyEdits();
115 } else if (remove_bookmark_) { 122 } else if (remove_bookmark_) {
116 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_); 123 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_);
117 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); 124 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_);
118 if (node) 125 if (node)
119 model->Remove(node); 126 model->Remove(node);
120 } 127 }
121 // |parent_combobox_| needs to be destroyed before |parent_model_| as it 128 if (!ios_promotion_viewed_) {
122 // uses |parent_model_| in its destructor. 129 // |parent_combobox_| needs to be destroyed before |parent_model_| as it
123 delete parent_combobox_; 130 // uses |parent_model_| in its destructor.
131 delete parent_combobox_;
132 }
124 } 133 }
125 134
126 void BookmarkBubbleView::WindowClosing() { 135 void BookmarkBubbleView::WindowClosing() {
127 // We have to reset |bubble_| here, not in our destructor, because we'll be 136 // We have to reset |bubble_| here, not in our destructor, because we'll be
128 // destroyed asynchronously and the shown state will be checked before then. 137 // destroyed asynchronously and the shown state will be checked before then.
129 DCHECK_EQ(bookmark_bubble_, this); 138 DCHECK_EQ(bookmark_bubble_, this);
130 bookmark_bubble_ = NULL; 139 bookmark_bubble_ = NULL;
131 140
132 if (observer_) 141 if (observer_)
133 observer_->OnBookmarkBubbleHidden(); 142 observer_->OnBookmarkBubbleHidden();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 layout->SkipColumns(2); 224 layout->SkipColumns(2);
216 layout->AddView(remove_button_); 225 layout->AddView(remove_button_);
217 layout->AddView(edit_button_); 226 layout->AddView(edit_button_);
218 layout->AddView(close_button_); 227 layout->AddView(close_button_);
219 228
220 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 229 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
221 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); 230 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN));
222 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); 231 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN));
223 } 232 }
224 233
234 gfx::ImageSkia BookmarkBubbleView::GetWindowIcon() {
235 #if defined(OS_WIN)
236 if (ios_promotion_viewed_) {
237 return desktop_ios_promotion::GetPromoImage(
238 GetNativeTheme()->GetSystemColor(
239 ui::NativeTheme::kColorId_TextfieldDefaultColor));
240 }
241 #endif
242 return gfx::ImageSkia();
243 }
244
245 bool BookmarkBubbleView::ShouldShowWindowIcon() const {
246 return ios_promotion_viewed_;
247 }
248
225 base::string16 BookmarkBubbleView::GetWindowTitle() const { 249 base::string16 BookmarkBubbleView::GetWindowTitle() const {
250 if (ios_promotion_viewed_) {
251 return desktop_ios_promotion::GetPromoTitle(
252 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE);
253 }
226 return l10n_util::GetStringUTF16(newly_bookmarked_ 254 return l10n_util::GetStringUTF16(newly_bookmarked_
227 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED 255 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED
228 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK); 256 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK);
229 } 257 }
230 258
231 const char* BookmarkBubbleView::GetClassName() const { 259 const char* BookmarkBubbleView::GetClassName() const {
232 return "BookmarkBubbleView"; 260 return "BookmarkBubbleView";
233 } 261 }
234 262
235 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { 263 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
(...skipping 26 matching lines...) Expand all
262 newly_bookmarked_(newly_bookmarked), 290 newly_bookmarked_(newly_bookmarked),
263 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), 291 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_),
264 BookmarkModelFactory::GetForBrowserContext(profile_) 292 BookmarkModelFactory::GetForBrowserContext(profile_)
265 ->GetMostRecentlyAddedUserNodeForURL(url)), 293 ->GetMostRecentlyAddedUserNodeForURL(url)),
266 remove_button_(nullptr), 294 remove_button_(nullptr),
267 edit_button_(nullptr), 295 edit_button_(nullptr),
268 close_button_(nullptr), 296 close_button_(nullptr),
269 title_tf_(nullptr), 297 title_tf_(nullptr),
270 parent_combobox_(nullptr), 298 parent_combobox_(nullptr),
271 remove_bookmark_(false), 299 remove_bookmark_(false),
272 apply_edits_(true) {} 300 apply_edits_(true),
301 ios_promotion_viewed_(false) {}
273 302
274 base::string16 BookmarkBubbleView::GetTitle() { 303 base::string16 BookmarkBubbleView::GetTitle() {
275 BookmarkModel* bookmark_model = 304 BookmarkModel* bookmark_model =
276 BookmarkModelFactory::GetForBrowserContext(profile_); 305 BookmarkModelFactory::GetForBrowserContext(profile_);
277 const BookmarkNode* node = 306 const BookmarkNode* node =
278 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); 307 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_);
279 if (node) 308 if (node)
280 return node->GetTitle(); 309 return node->GetTitle();
281 else 310 else
282 NOTREACHED(); 311 NOTREACHED();
(...skipping 24 matching lines...) Expand all
307 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); 336 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
308 // Set this so we remove the bookmark after the window closes. 337 // Set this so we remove the bookmark after the window closes.
309 remove_bookmark_ = true; 338 remove_bookmark_ = true;
310 apply_edits_ = false; 339 apply_edits_ = false;
311 GetWidget()->Close(); 340 GetWidget()->Close();
312 } else if (sender == edit_button_) { 341 } else if (sender == edit_button_) {
313 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 342 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
314 ShowEditor(); 343 ShowEditor();
315 } else { 344 } else {
316 DCHECK_EQ(close_button_, sender); 345 DCHECK_EQ(close_button_, sender);
346 #if defined(OS_WIN)
347 PrefService* prefs = profile_->GetPrefs();
348 const browser_sync::ProfileSyncService* sync_service =
349 ProfileSyncServiceFactory::GetForProfile(profile_);
350 if (desktop_ios_promotion::IsEligibleForIOSPromotion(
351 prefs, sync_service,
352 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) {
353 apply_edits_ = false;
sky 2017/03/27 20:03:55 Why are you resetting apply_edits_?
mrefaat 2017/03/29 19:50:18 changed that
354 ShowIOSPromotion();
355 } else {
356 GetWidget()->Close();
357 }
358 #else
317 GetWidget()->Close(); 359 GetWidget()->Close();
360 #endif
318 } 361 }
319 } 362 }
320 363
364 void BookmarkBubbleView::ShowIOSPromotion() {
sky 2017/03/27 20:03:55 Make order match header.
mrefaat 2017/03/29 19:50:18 Done.
365 RemoveAllChildViews(true);
sky 2017/03/27 20:03:55 Explicitly removing all the views is error prone (
mrefaat 2017/03/29 19:50:18 Done.
366 SetLayoutManager(new views::FillLayout);
367 ios_promotion_viewed_ = true;
368 ios_promo_view_ = new DesktopIOSPromotionBubbleView(
369 profile_, desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE);
370 AddChildView(ios_promo_view_);
371 GetWidget()->non_client_view()->ResetWindowControls();
372 GetWidget()->UpdateWindowIcon();
373 GetWidget()->UpdateWindowTitle();
374 SizeToContents();
375 }
376
321 void BookmarkBubbleView::ShowEditor() { 377 void BookmarkBubbleView::ShowEditor() {
322 const BookmarkNode* node = 378 const BookmarkNode* node =
323 BookmarkModelFactory::GetForBrowserContext(profile_) 379 BookmarkModelFactory::GetForBrowserContext(profile_)
324 ->GetMostRecentlyAddedUserNodeForURL(url_); 380 ->GetMostRecentlyAddedUserNodeForURL(url_);
325 gfx::NativeWindow native_parent = 381 gfx::NativeWindow native_parent =
326 anchor_widget() ? anchor_widget()->GetNativeWindow() 382 anchor_widget() ? anchor_widget()->GetNativeWindow()
327 : platform_util::GetTopLevel(parent_window()); 383 : platform_util::GetTopLevel(parent_window());
328 DCHECK(native_parent); 384 DCHECK(native_parent);
329 385
330 Profile* profile = profile_; 386 Profile* profile = profile_;
(...skipping 15 matching lines...) Expand all
346 if (node) { 402 if (node) {
347 const base::string16 new_title = title_tf_->text(); 403 const base::string16 new_title = title_tf_->text();
348 if (new_title != node->GetTitle()) { 404 if (new_title != node->GetTitle()) {
349 model->SetTitle(node, new_title); 405 model->SetTitle(node, new_title);
350 content::RecordAction( 406 content::RecordAction(
351 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 407 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
352 } 408 }
353 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 409 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
354 } 410 }
355 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698