| 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 (!is_showing_ios_promotion_ && |
| 275 IsIOSPromotionEligible( |
| 276 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) { |
| 277 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this); |
| 278 return footnote_view_; |
| 279 } |
| 280 |
| 272 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) | 281 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) |
| 273 return nullptr; | 282 return nullptr; |
| 274 | 283 |
| 275 base::RecordAction( | 284 base::RecordAction( |
| 276 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); | 285 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); |
| 277 | 286 |
| 278 return new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, | 287 return new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, |
| 279 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); | 288 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); |
| 280 } | 289 } |
| 281 | 290 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // Set this so we remove the bookmark after the window closes. | 353 // Set this so we remove the bookmark after the window closes. |
| 345 remove_bookmark_ = true; | 354 remove_bookmark_ = true; |
| 346 apply_edits_ = false; | 355 apply_edits_ = false; |
| 347 GetWidget()->Close(); | 356 GetWidget()->Close(); |
| 348 } else if (sender == edit_button_) { | 357 } else if (sender == edit_button_) { |
| 349 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 358 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
| 350 ShowEditor(); | 359 ShowEditor(); |
| 351 } else { | 360 } else { |
| 352 DCHECK_EQ(close_button_, sender); | 361 DCHECK_EQ(close_button_, sender); |
| 353 #if defined(OS_WIN) | 362 #if defined(OS_WIN) |
| 354 PrefService* prefs = profile_->GetPrefs(); | 363 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)) { | 364 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { |
| 360 ShowIOSPromotion(); | 365 ShowIOSPromotion( |
| 366 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); |
| 361 } else { | 367 } else { |
| 362 GetWidget()->Close(); | 368 GetWidget()->Close(); |
| 363 } | 369 } |
| 364 #else | 370 #else |
| 365 GetWidget()->Close(); | 371 GetWidget()->Close(); |
| 366 #endif | 372 #endif |
| 367 } | 373 } |
| 368 } | 374 } |
| 369 | 375 |
| 370 void BookmarkBubbleView::ShowEditor() { | 376 void BookmarkBubbleView::ShowEditor() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 396 const base::string16 new_title = title_tf_->text(); | 402 const base::string16 new_title = title_tf_->text(); |
| 397 if (new_title != node->GetTitle()) { | 403 if (new_title != node->GetTitle()) { |
| 398 model->SetTitle(node, new_title); | 404 model->SetTitle(node, new_title); |
| 399 base::RecordAction( | 405 base::RecordAction( |
| 400 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 406 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 401 } | 407 } |
| 402 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 408 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
| 403 } | 409 } |
| 404 } | 410 } |
| 405 | 411 |
| 412 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() { |
| 406 #if defined(OS_WIN) | 413 #if defined(OS_WIN) |
| 407 void BookmarkBubbleView::ShowIOSPromotion() { | 414 ShowIOSPromotion( |
| 415 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE); |
| 416 #endif |
| 417 } |
| 418 |
| 419 #if defined(OS_WIN) |
| 420 |
| 421 bool BookmarkBubbleView::IsIOSPromotionEligible( |
| 422 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
| 423 PrefService* prefs = profile_->GetPrefs(); |
| 424 const browser_sync::ProfileSyncService* sync_service = |
| 425 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 426 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, |
| 427 entry_point); |
| 428 } |
| 429 |
| 430 void BookmarkBubbleView::ShowIOSPromotion( |
| 431 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
| 408 DCHECK(!is_showing_ios_promotion_); | 432 DCHECK(!is_showing_ios_promotion_); |
| 409 RemoveChildView(bookmark_details_view_.get()); | 433 RemoveChildView(bookmark_details_view_.get()); |
| 434 views::BubbleFrameView* frame = static_cast<views::BubbleFrameView*>( |
| 435 GetWidget()->non_client_view()->frame_view()); |
| 436 frame->RemoveFootnoteView(); |
| 410 is_showing_ios_promotion_ = true; | 437 is_showing_ios_promotion_ = true; |
| 411 ios_promo_view_ = new DesktopIOSPromotionBubbleView( | 438 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); |
| 412 profile_, desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
| 413 AddChildView(ios_promo_view_); | 439 AddChildView(ios_promo_view_); |
| 414 GetWidget()->UpdateWindowIcon(); | 440 GetWidget()->UpdateWindowIcon(); |
| 415 GetWidget()->UpdateWindowTitle(); | 441 GetWidget()->UpdateWindowTitle(); |
| 416 // Resize the bubble so it has the same width as the parent bubble. | 442 // Resize the bubble so it has the same width as the parent bubble. |
| 417 ios_promo_view_->UpdateBubbleHeight(); | 443 ios_promo_view_->UpdateBubbleHeight(); |
| 418 } | 444 } |
| 419 #endif | 445 #endif |
| OLD | NEW |