| OLD | NEW |
| 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/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 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/fill_layout.h" | 38 #include "ui/views/layout/fill_layout.h" |
| 39 #include "ui/views/layout/grid_layout.h" | 39 #include "ui/views/layout/grid_layout.h" |
| 40 #include "ui/views/layout/layout_constants.h" | 40 #include "ui/views/layout/layout_constants.h" |
| 41 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
| 42 | 42 |
| 43 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 44 #include "chrome/browser/sync/profile_sync_service_factory.h" | 44 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 45 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" | 45 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" |
| 46 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_fo
otnote_view.h" |
| 46 #include "components/browser_sync/profile_sync_service.h" | 47 #include "components/browser_sync/profile_sync_service.h" |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 using base::UserMetricsAction; | 50 using base::UserMetricsAction; |
| 50 using bookmarks::BookmarkModel; | 51 using bookmarks::BookmarkModel; |
| 51 using bookmarks::BookmarkNode; | 52 using bookmarks::BookmarkNode; |
| 52 using views::ColumnSet; | 53 using views::ColumnSet; |
| 53 using views::GridLayout; | 54 using views::GridLayout; |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // |parent_combobox_| needs to be destroyed before |parent_model_| as it | 129 // |parent_combobox_| needs to be destroyed before |parent_model_| as it |
| 129 // uses |parent_model_| in its destructor. | 130 // uses |parent_model_| in its destructor. |
| 130 delete parent_combobox_; | 131 delete parent_combobox_; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void BookmarkBubbleView::WindowClosing() { | 134 void BookmarkBubbleView::WindowClosing() { |
| 134 // 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 |
| 135 // destroyed asynchronously and the shown state will be checked before then. | 136 // destroyed asynchronously and the shown state will be checked before then. |
| 136 DCHECK_EQ(bookmark_bubble_, this); | 137 DCHECK_EQ(bookmark_bubble_, this); |
| 137 bookmark_bubble_ = NULL; | 138 bookmark_bubble_ = NULL; |
| 139 is_showing_ios_promotion_ = false; |
| 138 | 140 |
| 139 if (observer_) | 141 if (observer_) |
| 140 observer_->OnBookmarkBubbleHidden(); | 142 observer_->OnBookmarkBubbleHidden(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 bool BookmarkBubbleView::AcceleratorPressed( | 145 bool BookmarkBubbleView::AcceleratorPressed( |
| 144 const ui::Accelerator& accelerator) { | 146 const ui::Accelerator& accelerator) { |
| 145 ui::KeyboardCode key_code = accelerator.key_code(); | 147 ui::KeyboardCode key_code = accelerator.key_code(); |
| 146 if (key_code == ui::VKEY_RETURN) { | 148 if (key_code == ui::VKEY_RETURN) { |
| 147 HandleButtonPressed(close_button_); | 149 HandleButtonPressed(close_button_); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 264 |
| 263 const char* BookmarkBubbleView::GetClassName() const { | 265 const char* BookmarkBubbleView::GetClassName() const { |
| 264 return "BookmarkBubbleView"; | 266 return "BookmarkBubbleView"; |
| 265 } | 267 } |
| 266 | 268 |
| 267 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 269 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
| 268 return title_tf_; | 270 return title_tf_; |
| 269 } | 271 } |
| 270 | 272 |
| 271 views::View* BookmarkBubbleView::CreateFootnoteView() { | 273 views::View* BookmarkBubbleView::CreateFootnoteView() { |
| 274 #if defined(OS_WIN) |
| 275 if (!is_showing_ios_promotion_ && |
| 276 IsIOSPromotionEligible( |
| 277 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) { |
| 278 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this); |
| 279 return footnote_view_; |
| 280 } |
| 281 #endif |
| 272 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) | 282 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) |
| 273 return nullptr; | 283 return nullptr; |
| 274 | 284 |
| 275 base::RecordAction( | 285 base::RecordAction( |
| 276 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); | 286 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); |
| 277 | 287 |
| 278 return new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, | 288 footnote_view_ = |
| 279 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); | 289 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, |
| 290 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); |
| 291 return footnote_view_; |
| 280 } | 292 } |
| 281 | 293 |
| 282 BookmarkBubbleView::BookmarkBubbleView( | 294 BookmarkBubbleView::BookmarkBubbleView( |
| 283 views::View* anchor_view, | 295 views::View* anchor_view, |
| 284 bookmarks::BookmarkBubbleObserver* observer, | 296 bookmarks::BookmarkBubbleObserver* observer, |
| 285 std::unique_ptr<BubbleSyncPromoDelegate> delegate, | 297 std::unique_ptr<BubbleSyncPromoDelegate> delegate, |
| 286 Profile* profile, | 298 Profile* profile, |
| 287 const GURL& url, | 299 const GURL& url, |
| 288 bool newly_bookmarked) | 300 bool newly_bookmarked) |
| 289 : LocationBarBubbleDelegateView(anchor_view, nullptr), | 301 : LocationBarBubbleDelegateView(anchor_view, nullptr), |
| 290 observer_(observer), | 302 observer_(observer), |
| 291 delegate_(std::move(delegate)), | 303 delegate_(std::move(delegate)), |
| 292 profile_(profile), | 304 profile_(profile), |
| 293 url_(url), | 305 url_(url), |
| 294 newly_bookmarked_(newly_bookmarked), | 306 newly_bookmarked_(newly_bookmarked), |
| 295 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), | 307 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), |
| 296 BookmarkModelFactory::GetForBrowserContext(profile_) | 308 BookmarkModelFactory::GetForBrowserContext(profile_) |
| 297 ->GetMostRecentlyAddedUserNodeForURL(url)), | 309 ->GetMostRecentlyAddedUserNodeForURL(url)), |
| 298 remove_button_(nullptr), | 310 remove_button_(nullptr), |
| 299 edit_button_(nullptr), | 311 edit_button_(nullptr), |
| 300 close_button_(nullptr), | 312 close_button_(nullptr), |
| 301 title_tf_(nullptr), | 313 title_tf_(nullptr), |
| 302 parent_combobox_(nullptr), | 314 parent_combobox_(nullptr), |
| 303 ios_promo_view_(nullptr), | 315 ios_promo_view_(nullptr), |
| 316 footnote_view_(nullptr), |
| 304 remove_bookmark_(false), | 317 remove_bookmark_(false), |
| 305 apply_edits_(true), | 318 apply_edits_(true), |
| 306 is_showing_ios_promotion_(false) { | 319 is_showing_ios_promotion_(false) { |
| 307 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); | 320 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); |
| 308 } | 321 } |
| 309 | 322 |
| 310 base::string16 BookmarkBubbleView::GetTitle() { | 323 base::string16 BookmarkBubbleView::GetTitle() { |
| 311 BookmarkModel* bookmark_model = | 324 BookmarkModel* bookmark_model = |
| 312 BookmarkModelFactory::GetForBrowserContext(profile_); | 325 BookmarkModelFactory::GetForBrowserContext(profile_); |
| 313 const BookmarkNode* node = | 326 const BookmarkNode* node = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 344 // Set this so we remove the bookmark after the window closes. | 357 // Set this so we remove the bookmark after the window closes. |
| 345 remove_bookmark_ = true; | 358 remove_bookmark_ = true; |
| 346 apply_edits_ = false; | 359 apply_edits_ = false; |
| 347 GetWidget()->Close(); | 360 GetWidget()->Close(); |
| 348 } else if (sender == edit_button_) { | 361 } else if (sender == edit_button_) { |
| 349 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 362 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
| 350 ShowEditor(); | 363 ShowEditor(); |
| 351 } else { | 364 } else { |
| 352 DCHECK_EQ(close_button_, sender); | 365 DCHECK_EQ(close_button_, sender); |
| 353 #if defined(OS_WIN) | 366 #if defined(OS_WIN) |
| 354 PrefService* prefs = profile_->GetPrefs(); | 367 if (IsIOSPromotionEligible( |
| 355 const browser_sync::ProfileSyncService* sync_service = | |
| 356 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 357 if (desktop_ios_promotion::IsEligibleForIOSPromotion( | |
| 358 prefs, sync_service, | |
| 359 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { | 368 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { |
| 360 ShowIOSPromotion(); | 369 ShowIOSPromotion( |
| 370 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); |
| 361 } else { | 371 } else { |
| 362 GetWidget()->Close(); | 372 GetWidget()->Close(); |
| 363 } | 373 } |
| 364 #else | 374 #else |
| 365 GetWidget()->Close(); | 375 GetWidget()->Close(); |
| 366 #endif | 376 #endif |
| 367 } | 377 } |
| 368 } | 378 } |
| 369 | 379 |
| 370 void BookmarkBubbleView::ShowEditor() { | 380 void BookmarkBubbleView::ShowEditor() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 396 const base::string16 new_title = title_tf_->text(); | 406 const base::string16 new_title = title_tf_->text(); |
| 397 if (new_title != node->GetTitle()) { | 407 if (new_title != node->GetTitle()) { |
| 398 model->SetTitle(node, new_title); | 408 model->SetTitle(node, new_title); |
| 399 base::RecordAction( | 409 base::RecordAction( |
| 400 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 410 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 401 } | 411 } |
| 402 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 412 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
| 403 } | 413 } |
| 404 } | 414 } |
| 405 | 415 |
| 416 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() { |
| 406 #if defined(OS_WIN) | 417 #if defined(OS_WIN) |
| 407 void BookmarkBubbleView::ShowIOSPromotion() { | 418 ShowIOSPromotion( |
| 419 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE); |
| 420 #endif |
| 421 } |
| 422 |
| 423 #if defined(OS_WIN) |
| 424 |
| 425 bool BookmarkBubbleView::IsIOSPromotionEligible( |
| 426 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
| 427 PrefService* prefs = profile_->GetPrefs(); |
| 428 const browser_sync::ProfileSyncService* sync_service = |
| 429 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 430 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, |
| 431 entry_point); |
| 432 } |
| 433 |
| 434 void BookmarkBubbleView::ShowIOSPromotion( |
| 435 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
| 408 DCHECK(!is_showing_ios_promotion_); | 436 DCHECK(!is_showing_ios_promotion_); |
| 409 RemoveChildView(bookmark_details_view_.get()); | 437 RemoveChildView(bookmark_details_view_.get()); |
| 438 delete footnote_view_; |
| 439 footnote_view_ = nullptr; |
| 410 is_showing_ios_promotion_ = true; | 440 is_showing_ios_promotion_ = true; |
| 411 ios_promo_view_ = new DesktopIOSPromotionBubbleView( | 441 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); |
| 412 profile_, desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
| 413 AddChildView(ios_promo_view_); | 442 AddChildView(ios_promo_view_); |
| 414 GetWidget()->UpdateWindowIcon(); | 443 GetWidget()->UpdateWindowIcon(); |
| 415 GetWidget()->UpdateWindowTitle(); | 444 GetWidget()->UpdateWindowTitle(); |
| 416 // Resize the bubble so it has the same width as the parent bubble. | 445 // Resize the bubble so it has the same width as the parent bubble. |
| 417 ios_promo_view_->UpdateBubbleHeight(); | 446 ios_promo_view_->UpdateBubbleHeight(); |
| 418 } | 447 } |
| 419 #endif | 448 #endif |
| OLD | NEW |