Chromium Code Reviews| 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 "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/platform_util.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" | 14 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" |
| 14 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" | 15 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" |
| 16 #include "chrome/browser/ui/browser_dialogs.h" | |
| 15 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 17 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
| 16 #include "chrome/browser/ui/views/bookmarks/bookmark_sync_promo_view.h" | 18 #include "chrome/browser/ui/views/bookmarks/bookmark_sync_promo_view.h" |
| 17 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
| 19 #include "components/bookmarks/browser/bookmark_utils.h" | 21 #include "components/bookmarks/browser/bookmark_utils.h" |
| 20 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
| 21 #include "ui/accessibility/ax_view_state.h" | 23 #include "ui/accessibility/ax_view_state.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 private: | 58 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(UnsizedCombobox); | 59 DISALLOW_COPY_AND_ASSIGN(UnsizedCombobox); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 } // namespace | 62 } // namespace |
| 61 | 63 |
| 62 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; | 64 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; |
| 63 | 65 |
| 64 // static | 66 // static |
| 65 void BookmarkBubbleView::ShowBubble(views::View* anchor_view, | 67 void BookmarkBubbleView::ShowBubble(views::View* anchor_view, |
| 68 const gfx::Rect& anchor_rect, | |
| 69 gfx::NativeView parent_window, | |
| 66 bookmarks::BookmarkBubbleObserver* observer, | 70 bookmarks::BookmarkBubbleObserver* observer, |
| 67 scoped_ptr<BookmarkBubbleDelegate> delegate, | 71 scoped_ptr<BookmarkBubbleDelegate> delegate, |
| 68 Profile* profile, | 72 Profile* profile, |
| 69 const GURL& url, | 73 const GURL& url, |
| 70 bool newly_bookmarked) { | 74 bool newly_bookmarked) { |
| 71 if (bookmark_bubble_) | 75 if (bookmark_bubble_) |
| 72 return; | 76 return; |
| 73 | 77 |
| 74 bookmark_bubble_ = new BookmarkBubbleView(anchor_view, | 78 bookmark_bubble_ = new BookmarkBubbleView(anchor_view, |
| 75 observer, | 79 observer, |
| 76 delegate.Pass(), | 80 delegate.Pass(), |
| 77 profile, | 81 profile, |
| 78 url, | 82 url, |
| 79 newly_bookmarked); | 83 newly_bookmarked); |
| 84 if (!anchor_view) { | |
| 85 bookmark_bubble_->SetAnchorRect(anchor_rect); | |
| 86 bookmark_bubble_->set_parent_window(parent_window); | |
| 87 } | |
| 80 views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show(); | 88 views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show(); |
| 81 // Select the entire title textfield contents when the bubble is first shown. | 89 // Select the entire title textfield contents when the bubble is first shown. |
| 82 bookmark_bubble_->title_tf_->SelectAll(true); | 90 bookmark_bubble_->title_tf_->SelectAll(true); |
| 83 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 91 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 84 | 92 |
| 85 if (bookmark_bubble_->observer_) { | 93 if (bookmark_bubble_->observer_) { |
| 86 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); | 94 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); |
| 87 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); | 95 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); |
| 88 bookmark_bubble_->observer_->OnBookmarkBubbleShown(node); | 96 bookmark_bubble_->observer_->OnBookmarkBubbleShown(node); |
| 89 } | 97 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 ShowEditor(); | 347 ShowEditor(); |
| 340 } else { | 348 } else { |
| 341 DCHECK_EQ(close_button_, sender); | 349 DCHECK_EQ(close_button_, sender); |
| 342 GetWidget()->Close(); | 350 GetWidget()->Close(); |
| 343 } | 351 } |
| 344 } | 352 } |
| 345 | 353 |
| 346 void BookmarkBubbleView::ShowEditor() { | 354 void BookmarkBubbleView::ShowEditor() { |
| 347 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 355 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
| 348 profile_)->GetMostRecentlyAddedUserNodeForURL(url_); | 356 profile_)->GetMostRecentlyAddedUserNodeForURL(url_); |
| 349 views::Widget* parent = anchor_widget(); | 357 gfx::NativeWindow native_window = |
|
tapted
2015/08/25 00:00:45
nit: native_window -> parent (or native_parent) -
jackhou1
2015/08/25 04:55:39
Done.
| |
| 350 DCHECK(parent); | 358 anchor_widget() ? anchor_widget()->GetNativeWindow() |
| 359 : platform_util::GetTopLevel(parent_window()); | |
| 360 DCHECK(native_window); | |
| 351 | 361 |
| 352 Profile* profile = profile_; | 362 Profile* profile = profile_; |
| 353 ApplyEdits(); | 363 ApplyEdits(); |
| 354 GetWidget()->Close(); | 364 GetWidget()->Close(); |
| 355 | 365 |
| 356 if (node && parent) | 366 if (node && native_window) |
| 357 BookmarkEditor::Show(parent->GetNativeWindow(), profile, | 367 BookmarkEditor::Show(native_window, profile, |
| 358 BookmarkEditor::EditDetails::EditNode(node), | 368 BookmarkEditor::EditDetails::EditNode(node), |
| 359 BookmarkEditor::SHOW_TREE); | 369 BookmarkEditor::SHOW_TREE); |
| 360 } | 370 } |
| 361 | 371 |
| 362 void BookmarkBubbleView::ApplyEdits() { | 372 void BookmarkBubbleView::ApplyEdits() { |
| 363 // Set this to make sure we don't attempt to apply edits again. | 373 // Set this to make sure we don't attempt to apply edits again. |
| 364 apply_edits_ = false; | 374 apply_edits_ = false; |
| 365 | 375 |
| 366 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); | 376 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
| 367 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); | 377 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); |
| 368 if (node) { | 378 if (node) { |
| 369 const base::string16 new_title = title_tf_->text(); | 379 const base::string16 new_title = title_tf_->text(); |
| 370 if (new_title != node->GetTitle()) { | 380 if (new_title != node->GetTitle()) { |
| 371 model->SetTitle(node, new_title); | 381 model->SetTitle(node, new_title); |
| 372 content::RecordAction( | 382 content::RecordAction( |
| 373 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 383 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 374 } | 384 } |
| 375 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 385 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
| 376 } | 386 } |
| 377 } | 387 } |
| OLD | NEW |