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

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

Issue 1307533002: [Mac] Enable MacViews bookmark bubble behind --enable-mac-views-dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@modal
Patch Set: Created 5 years, 4 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/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"
14 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h"
13 #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"
14 #include "chrome/browser/ui/sync/sync_promo_ui.h" 17 #include "chrome/browser/ui/sync/sync_promo_ui.h"
15 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.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"
25 #include "ui/views/bubble/bubble_frame_view.h" 27 #include "ui/views/bubble/bubble_frame_view.h"
(...skipping 30 matching lines...) Expand all
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,
66 BookmarkBubbleViewObserver* observer, 68 const gfx::Rect& anchor_rect,
69 gfx::NativeView parent_window,
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 bookmark_bubble_->observer_->OnBookmarkBubbleShown(url); 94 bookmark_bubble_->observer_->OnBookmarkBubbleShown(url);
87 } 95 }
88 96
89 void BookmarkBubbleView::Hide() { 97 void BookmarkBubbleView::Hide() {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 const char* BookmarkBubbleView::GetClassName() const { 265 const char* BookmarkBubbleView::GetClassName() const {
258 return "BookmarkBubbleView"; 266 return "BookmarkBubbleView";
259 } 267 }
260 268
261 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { 269 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
262 return title_tf_; 270 return title_tf_;
263 } 271 }
264 272
265 BookmarkBubbleView::BookmarkBubbleView( 273 BookmarkBubbleView::BookmarkBubbleView(
266 views::View* anchor_view, 274 views::View* anchor_view,
267 BookmarkBubbleViewObserver* observer, 275 bookmarks::BookmarkBubbleObserver* observer,
268 scoped_ptr<BookmarkBubbleDelegate> delegate, 276 scoped_ptr<BookmarkBubbleDelegate> delegate,
269 Profile* profile, 277 Profile* profile,
270 const GURL& url, 278 const GURL& url,
271 bool newly_bookmarked) 279 bool newly_bookmarked)
272 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 280 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
273 observer_(observer), 281 observer_(observer),
274 delegate_(delegate.Pass()), 282 delegate_(delegate.Pass()),
275 profile_(profile), 283 profile_(profile),
276 url_(url), 284 url_(url),
277 newly_bookmarked_(newly_bookmarked), 285 newly_bookmarked_(newly_bookmarked),
278 parent_model_( 286 parent_model_(BookmarkModelFactory::GetForProfile(profile_),
279 BookmarkModelFactory::GetForProfile(profile_), 287 BookmarkModelFactory::GetForProfile(profile_)
280 BookmarkModelFactory::GetForProfile(profile_)-> 288 ->GetMostRecentlyAddedUserNodeForURL(url)),
281 GetMostRecentlyAddedUserNodeForURL(url)),
282 remove_button_(NULL), 289 remove_button_(NULL),
283 edit_button_(NULL), 290 edit_button_(NULL),
284 close_button_(NULL), 291 close_button_(NULL),
285 title_tf_(NULL), 292 title_tf_(NULL),
286 parent_combobox_(NULL), 293 parent_combobox_(NULL),
287 sync_promo_view_(NULL), 294 sync_promo_view_(NULL),
288 remove_bookmark_(false), 295 remove_bookmark_(false),
289 apply_edits_(true) { 296 apply_edits_(true) {
290 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); 297 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0));
291 // Compensate for built-in vertical padding in the anchor view's image. 298 // Compensate for built-in vertical padding in the anchor view's image.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ShowEditor(); 343 ShowEditor();
337 } else { 344 } else {
338 DCHECK_EQ(close_button_, sender); 345 DCHECK_EQ(close_button_, sender);
339 GetWidget()->Close(); 346 GetWidget()->Close();
340 } 347 }
341 } 348 }
342 349
343 void BookmarkBubbleView::ShowEditor() { 350 void BookmarkBubbleView::ShowEditor() {
344 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( 351 const BookmarkNode* node = BookmarkModelFactory::GetForProfile(
345 profile_)->GetMostRecentlyAddedUserNodeForURL(url_); 352 profile_)->GetMostRecentlyAddedUserNodeForURL(url_);
346 views::Widget* parent = anchor_widget(); 353 gfx::NativeWindow native_window =
347 DCHECK(parent); 354 anchor_widget() ? anchor_widget()->GetNativeWindow()
355 : platform_util::GetTopLevel(parent_window());
356 DCHECK(native_window);
348 357
349 Profile* profile = profile_; 358 Profile* profile = profile_;
350 ApplyEdits(); 359 ApplyEdits();
351 GetWidget()->Close(); 360 GetWidget()->Close();
352 361
353 if (node && parent) 362 if (node && native_window)
354 BookmarkEditor::Show(parent->GetNativeWindow(), profile, 363 chrome::ShowBookmarkEditorView(native_window, profile,
355 BookmarkEditor::EditDetails::EditNode(node), 364 BookmarkEditor::EditDetails::EditNode(node),
356 BookmarkEditor::SHOW_TREE); 365 BookmarkEditor::SHOW_TREE);
357 } 366 }
358 367
359 void BookmarkBubbleView::ApplyEdits() { 368 void BookmarkBubbleView::ApplyEdits() {
360 // Set this to make sure we don't attempt to apply edits again. 369 // Set this to make sure we don't attempt to apply edits again.
361 apply_edits_ = false; 370 apply_edits_ = false;
362 371
363 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); 372 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_);
364 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); 373 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_);
365 if (node) { 374 if (node) {
366 const base::string16 new_title = title_tf_->text(); 375 const base::string16 new_title = title_tf_->text();
367 if (new_title != node->GetTitle()) { 376 if (new_title != node->GetTitle()) {
368 model->SetTitle(node, new_title); 377 model->SetTitle(node, new_title);
369 content::RecordAction( 378 content::RecordAction(
370 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 379 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
371 } 380 }
372 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 381 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
373 } 382 }
374 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698