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

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

Issue 8368016: Rebase BookmarkBubble on the new views bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add Textfield::[set_]select_all_on_focus, use GetInitiallyFocusedView. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string16.h" 7 #include "base/string16.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/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_editor.h" 11 #include "chrome/browser/bookmarks/bookmark_editor.h"
12 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "chrome/browser/bookmarks/bookmark_utils.h" 13 #include "chrome/browser/bookmarks/bookmark_utils.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/views/bubble/bubble.h"
18 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
19 #include "content/browser/user_metrics.h" 18 #include "content/browser/user_metrics.h"
20 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
21 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
23 #include "ui/base/keycodes/keyboard_codes.h" 22 #include "ui/base/keycodes/keyboard_codes.h"
24 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/canvas.h"
27 #include "views/controls/button/text_button.h" 25 #include "views/controls/button/text_button.h"
28 #include "views/controls/label.h" 26 #include "views/controls/label.h"
29 #include "views/controls/link.h" 27 #include "views/controls/link.h"
30 #include "views/controls/textfield/textfield.h" 28 #include "views/controls/textfield/textfield.h"
31 #include "views/events/event.h" 29 #include "views/events/event.h"
32 #include "views/focus/focus_manager.h"
33 #include "views/layout/grid_layout.h" 30 #include "views/layout/grid_layout.h"
34 #include "views/layout/layout_constants.h" 31 #include "views/layout/layout_constants.h"
35 #include "views/window/client_view.h" 32 #include "views/widget/widget.h"
36
37 #if defined(TOOLKIT_USES_GTK)
38 #include "views/widget/native_widget_gtk.h"
39 #endif
40 33
41 using views::ColumnSet; 34 using views::ColumnSet;
42 using views::GridLayout; 35 using views::GridLayout;
43 36
44 // Padding between "Title:" and the actual title. 37 // Padding between "Title:" and the actual title.
45 static const int kTitlePadding = 4; 38 static const int kTitlePadding = 4;
46 39
47 // Minimum width for the fields - they will push out the size of the bubble if 40 // Minimum width for the fields - they will push out the size of the bubble if
48 // necessary. This should be big enough so that the field pushes the right side 41 // necessary. This should be big enough so that the field pushes the right side
49 // of the bubble far enough so that the edit button's left edge is to the right 42 // of the bubble far enough so that the edit button's left edge is to the right
50 // of the field's left edge. 43 // of the field's left edge.
51 static const int kMinimumFieldSize = 180; 44 static const int kMinimumFieldSize = 180;
52 45
46 // TODO(msw): Get color from theme/window color.
47 static const SkColor kColor = SK_ColorWHITE;
48
53 // Declared in browser_dialogs.h so callers don't have to depend on our header. 49 // Declared in browser_dialogs.h so callers don't have to depend on our header.
54 50
55 namespace browser { 51 namespace browser {
56 52
57 void ShowBookmarkBubbleView(views::Widget* parent, 53 void ShowBookmarkBubbleView(views::Widget* parent,
58 const gfx::Rect& bounds, 54 const gfx::Point& anchor,
59 BubbleDelegate* delegate,
60 Profile* profile, 55 Profile* profile,
61 const GURL& url, 56 const GURL& url,
62 bool newly_bookmarked) { 57 bool newly_bookmarked) {
63 BookmarkBubbleView::Show(parent, bounds, delegate, profile, url, 58 BookmarkBubbleView::ShowBubble(parent, anchor, profile, url,
64 newly_bookmarked); 59 newly_bookmarked);
65 } 60 }
66 61
67 void HideBookmarkBubbleView() { 62 void HideBookmarkBubbleView() {
68 BookmarkBubbleView::Hide(); 63 BookmarkBubbleView::Hide();
69 } 64 }
70 65
71 bool IsBookmarkBubbleViewShowing() { 66 bool IsBookmarkBubbleViewShowing() {
72 return BookmarkBubbleView::IsShowing(); 67 return BookmarkBubbleView::IsShowing();
73 } 68 }
74 69
75 } // namespace browser 70 } // namespace browser
76 71
77 // BookmarkBubbleView --------------------------------------------------------- 72 // BookmarkBubbleView ---------------------------------------------------------
78 73
79 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; 74 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL;
80 75
81 // static 76 // static
82 void BookmarkBubbleView::Show(views::Widget* parent, 77 void BookmarkBubbleView::ShowBubble(views::Widget* parent,
83 const gfx::Rect& bounds, 78 const gfx::Point& anchor,
84 BubbleDelegate* delegate, 79 Profile* profile,
85 Profile* profile, 80 const GURL& url,
86 const GURL& url, 81 bool newly_bookmarked) {
87 bool newly_bookmarked) {
88 if (IsShowing()) 82 if (IsShowing())
89 return; 83 return;
90 84
91 bookmark_bubble_ = new BookmarkBubbleView(delegate, profile, url, 85 bookmark_bubble_ =
92 newly_bookmarked); 86 new BookmarkBubbleView(parent, anchor, profile, url, newly_bookmarked);
93 Bubble* bubble = Bubble::Show( 87 views::BubbleDelegateView::CreateBubble(bookmark_bubble_, parent);
94 parent, bounds, views::BubbleBorder::TOP_RIGHT, 88 bookmark_bubble_->Show();
95 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bookmark_bubble_, 89
96 bookmark_bubble_);
97 // |bubble_| can be set to NULL in BubbleClosing when we close the bubble
98 // asynchronously. However, that can happen during the Show call above if the
99 // window loses activation while we are getting to ready to show the bubble,
100 // so we must check to make sure we still have a valid bubble before
101 // proceeding.
102 if (!bookmark_bubble_)
103 return;
104 bookmark_bubble_->set_bubble(bubble);
105 bubble->SizeToContents();
106 GURL url_ptr(url); 90 GURL url_ptr(url);
107 content::NotificationService::current()->Notify( 91 content::NotificationService::current()->Notify(
108 chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN, 92 chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN,
109 content::Source<Profile>(profile->GetOriginalProfile()), 93 content::Source<Profile>(profile->GetOriginalProfile()),
110 content::Details<GURL>(&url_ptr)); 94 content::Details<GURL>(&url_ptr));
111 } 95 }
112 96
113 // static 97 // static
114 bool BookmarkBubbleView::IsShowing() { 98 bool BookmarkBubbleView::IsShowing() {
115 return bookmark_bubble_ != NULL; 99 return bookmark_bubble_ != NULL;
116 } 100 }
117 101
118 void BookmarkBubbleView::Hide() { 102 void BookmarkBubbleView::Hide() {
119 if (IsShowing()) 103 if (IsShowing())
120 bookmark_bubble_->Close(); 104 bookmark_bubble_->GetWidget()->Close();
121 } 105 }
122 106
123 BookmarkBubbleView::~BookmarkBubbleView() { 107 BookmarkBubbleView::~BookmarkBubbleView() {
124 if (apply_edits_) { 108 if (apply_edits_) {
125 ApplyEdits(); 109 ApplyEdits();
126 } else if (remove_bookmark_) { 110 } else if (remove_bookmark_) {
127 BookmarkModel* model = profile_->GetBookmarkModel(); 111 BookmarkModel* model = profile_->GetBookmarkModel();
128 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); 112 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
129 if (node) 113 if (node)
130 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); 114 model->Remove(node->parent(), node->parent()->GetIndexOf(node));
131 } 115 }
132 } 116 }
133 117
134 void BookmarkBubbleView::BubbleShown() { 118 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
135 DCHECK(GetWidget()); 119 return title_tf_;
136 GetFocusManager()->RegisterAccelerator( 120 }
137 views::Accelerator(ui::VKEY_RETURN, false, false, false), this);
138 121
139 title_tf_->RequestFocus(); 122 void BookmarkBubbleView::WindowClosing() {
140 title_tf_->SelectAll(); 123 // We have to reset |bubble_| here, not in our destructor, because we'll be
141 } 124 // destroyed asynchronously and the shown state will be checked before then.
125 DCHECK(bookmark_bubble_ == this);
126 bookmark_bubble_ = NULL;
127
128 content::NotificationService::current()->Notify(
129 chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN,
130 content::Source<Profile>(profile_->GetOriginalProfile()),
131 content::NotificationService::NoDetails());
132 }
142 133
143 bool BookmarkBubbleView::AcceleratorPressed( 134 bool BookmarkBubbleView::AcceleratorPressed(
144 const views::Accelerator& accelerator) { 135 const views::Accelerator& accelerator) {
145 if (accelerator.key_code() != ui::VKEY_RETURN) 136 if (accelerator.key_code() == ui::VKEY_RETURN) {
146 return false; 137 if (edit_button_->HasFocus())
138 HandleButtonPressed(edit_button_);
139 else
140 HandleButtonPressed(close_button_);
141 return true;
142 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) {
143 remove_bookmark_ = newly_bookmarked_;
144 apply_edits_ = false;
145 }
147 146
148 if (edit_button_->HasFocus()) 147 return BubbleDelegateView::AcceleratorPressed(accelerator);
149 HandleButtonPressed(edit_button_);
150 else
151 HandleButtonPressed(close_button_);
152 return true;
153 }
154
155 void BookmarkBubbleView::ViewHierarchyChanged(bool is_add,
156 views::View* parent,
157 views::View* child) {
158 if (is_add && child == this)
159 Init();
160 }
161
162 BookmarkBubbleView::BookmarkBubbleView(BubbleDelegate* delegate,
163 Profile* profile,
164 const GURL& url,
165 bool newly_bookmarked)
166 : delegate_(delegate),
167 profile_(profile),
168 url_(url),
169 newly_bookmarked_(newly_bookmarked),
170 parent_model_(
171 profile_->GetBookmarkModel(),
172 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)),
173 remove_bookmark_(false),
174 apply_edits_(true) {
175 } 148 }
176 149
177 void BookmarkBubbleView::Init() { 150 void BookmarkBubbleView::Init() {
178 remove_link_ = new views::Link(l10n_util::GetStringUTF16( 151 remove_link_ = new views::Link(l10n_util::GetStringUTF16(
179 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); 152 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK));
180 remove_link_->set_listener(this); 153 remove_link_->set_listener(this);
181 remove_link_->SetBackgroundColor(Bubble::kBackgroundColor);
182 154
183 edit_button_ = new views::NativeTextButton( 155 edit_button_ = new views::NativeTextButton(
184 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); 156 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS));
185 157
186 close_button_ = new views::NativeTextButton( 158 close_button_ = new views::NativeTextButton(
187 this, l10n_util::GetStringUTF16(IDS_DONE)); 159 this, l10n_util::GetStringUTF16(IDS_DONE));
188 close_button_->SetIsDefault(true); 160 close_button_->SetIsDefault(true);
189 161
190 views::Label* combobox_label = new views::Label( 162 views::Label* combobox_label = new views::Label(
191 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); 163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT));
192 combobox_label->SetBackgroundColor(Bubble::kBackgroundColor);
193 164
194 parent_combobox_ = new views::Combobox(&parent_model_); 165 parent_combobox_ = new views::Combobox(&parent_model_);
195 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); 166 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index());
196 parent_combobox_->set_listener(this); 167 parent_combobox_->set_listener(this);
197 parent_combobox_->SetAccessibleName(combobox_label->GetText()); 168 parent_combobox_->SetAccessibleName(combobox_label->GetText());
198 169
199 views::Label* title_label = new views::Label( 170 views::Label* title_label = new views::Label(
200 l10n_util::GetStringUTF16( 171 l10n_util::GetStringUTF16(
201 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : 172 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED :
202 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); 173 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK));
203 title_label->SetFont( 174 title_label->SetFont(
204 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); 175 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont));
205 title_label->SetBackgroundColor(Bubble::kBackgroundColor);
206 title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117)); 176 title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117));
207 177
208 GridLayout* layout = new GridLayout(this); 178 GridLayout* layout = new GridLayout(this);
209 SetLayoutManager(layout); 179 SetLayoutManager(layout);
210 180
211 ColumnSet* cs = layout->AddColumnSet(0); 181 ColumnSet* cs = layout->AddColumnSet(0);
212 182
213 // Top (title) row. 183 // Top (title) row.
214 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, 184 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF,
215 0, 0); 185 0, 0);
(...skipping 22 matching lines...) Expand all
238 GridLayout::USE_PREF, 0, 0); 208 GridLayout::USE_PREF, 0, 0);
239 209
240 layout->StartRow(0, 0); 210 layout->StartRow(0, 0);
241 layout->AddView(title_label); 211 layout->AddView(title_label);
242 layout->AddView(remove_link_); 212 layout->AddView(remove_link_);
243 213
244 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 214 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
245 layout->StartRow(0, 2); 215 layout->StartRow(0, 2);
246 views::Label* label = new views::Label( 216 views::Label* label = new views::Label(
247 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); 217 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT));
248 label->SetBackgroundColor(Bubble::kBackgroundColor);
249 layout->AddView(label); 218 layout->AddView(label);
250 title_tf_ = new views::Textfield(); 219 title_tf_ = new views::Textfield();
220 title_tf_->set_select_all_on_focus(true);
251 title_tf_->SetText(GetTitle()); 221 title_tf_->SetText(GetTitle());
252 layout->AddView(title_tf_); 222 layout->AddView(title_tf_);
253 223
254 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 224 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
255 225
256 layout->StartRow(0, 2); 226 layout->StartRow(0, 2);
257 layout->AddView(combobox_label); 227 layout->AddView(combobox_label);
258 layout->AddView(parent_combobox_); 228 layout->AddView(parent_combobox_);
259 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 229 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
260 230
261 layout->StartRow(0, 3); 231 layout->StartRow(0, 3);
262 layout->AddView(edit_button_); 232 layout->AddView(edit_button_);
263 layout->AddView(close_button_); 233 layout->AddView(close_button_);
234
235 AddAccelerator(views::Accelerator(ui::VKEY_RETURN, 0));
236 }
237
238 BookmarkBubbleView::BookmarkBubbleView(views::Widget* parent,
239 const gfx::Point& anchor,
240 Profile* profile,
241 const GURL& url,
242 bool newly_bookmarked)
243 : BubbleDelegateView(anchor, views::BubbleBorder::TOP_RIGHT, kColor),
244 parent_(parent),
245 profile_(profile),
246 url_(url),
247 newly_bookmarked_(newly_bookmarked),
248 parent_model_(
249 profile_->GetBookmarkModel(),
250 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)),
251 remove_bookmark_(false),
252 apply_edits_(true) {
264 } 253 }
265 254
266 string16 BookmarkBubbleView::GetTitle() { 255 string16 BookmarkBubbleView::GetTitle() {
267 BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); 256 BookmarkModel* bookmark_model= profile_->GetBookmarkModel();
268 const BookmarkNode* node = 257 const BookmarkNode* node =
269 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); 258 bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
270 if (node) 259 if (node)
271 return node->GetTitle(); 260 return node->GetTitle();
272 else 261 else
273 NOTREACHED(); 262 NOTREACHED();
274 return string16(); 263 return string16();
275 } 264 }
276 265
277 void BookmarkBubbleView::ButtonPressed( 266 void BookmarkBubbleView::ButtonPressed(
278 views::Button* sender, const views::Event& event) { 267 views::Button* sender, const views::Event& event) {
279 HandleButtonPressed(sender); 268 HandleButtonPressed(sender);
280 } 269 }
281 270
282 void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) { 271 void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) {
283 DCHECK(source == remove_link_); 272 DCHECK(source == remove_link_);
284 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); 273 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
285 274
286 // Set this so we remove the bookmark after the window closes. 275 // Set this so we remove the bookmark after the window closes.
287 remove_bookmark_ = true; 276 remove_bookmark_ = true;
288 apply_edits_ = false; 277 apply_edits_ = false;
289 278 StartFade(false);
290 bubble_->set_fade_away_on_close(true);
291 Close();
292 } 279 }
293 280
294 void BookmarkBubbleView::ItemChanged(views::Combobox* combobox, 281 void BookmarkBubbleView::ItemChanged(views::Combobox* combobox,
295 int prev_index, 282 int prev_index,
296 int new_index) { 283 int new_index) {
297 if (new_index + 1 == parent_model_.GetItemCount()) { 284 if (new_index + 1 == parent_model_.GetItemCount()) {
298 UserMetrics::RecordAction( 285 UserMetrics::RecordAction(
299 UserMetricsAction("BookmarkBubble_EditFromCombobox")); 286 UserMetricsAction("BookmarkBubble_EditFromCombobox"));
300
301 ShowEditor(); 287 ShowEditor();
302 return;
303 } 288 }
304 } 289 }
305 290
306 void BookmarkBubbleView::BubbleClosing(Bubble* bubble,
307 bool closed_by_escape) {
308 if (closed_by_escape) {
309 remove_bookmark_ = newly_bookmarked_;
310 apply_edits_ = false;
311 }
312
313 // We have to reset |bubble_| here, not in our destructor, because we'll be
314 // destroyed asynchronously and the shown state will be checked before then.
315 DCHECK(bookmark_bubble_ == this);
316 bookmark_bubble_ = NULL;
317
318 if (delegate_)
319 delegate_->BubbleClosing(bubble, closed_by_escape);
320 content::NotificationService::current()->Notify(
321 chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN,
322 content::Source<Profile>(profile_->GetOriginalProfile()),
323 content::NotificationService::NoDetails());
324 }
325
326 bool BookmarkBubbleView::CloseOnEscape() {
327 return delegate_ ? delegate_->CloseOnEscape() : true;
328 }
329
330 bool BookmarkBubbleView::FadeInOnShow() {
331 return false;
332 }
333
334 string16 BookmarkBubbleView::GetAccessibleName() {
335 return l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK);
336 }
337
338 void BookmarkBubbleView::Close() {
339 ApplyEdits();
340 GetWidget()->Close();
341 }
342
343 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { 291 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) {
344 if (sender == edit_button_) { 292 if (sender == edit_button_) {
345 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 293 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
346 bubble_->set_fade_away_on_close(true);
347 ShowEditor(); 294 ShowEditor();
348 } else { 295 } else {
349 DCHECK(sender == close_button_); 296 DCHECK_EQ(sender, close_button_);
350 bubble_->set_fade_away_on_close(true); 297 StartFade(false);
351 Close();
352 } 298 }
353 // WARNING: we've most likely been deleted when CloseWindow returns.
354 } 299 }
355 300
356 void BookmarkBubbleView::ShowEditor() { 301 void BookmarkBubbleView::ShowEditor() {
357 const BookmarkNode* node = 302 const BookmarkNode* node =
358 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); 303 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_);
304 views::Widget* parent = parent_;
305 Profile* profile = profile_;
306 ApplyEdits();
307 GetWidget()->Close();
359 308
360 #if defined(USE_AURA) 309 if (node)
361 NOTIMPLEMENTED(); 310 BookmarkEditor::Show(parent->GetNativeWindow(), profile,
362 gfx::NativeView parent = NULL;
363 #elif defined(OS_WIN)
364 // Parent the editor to our root ancestor (not the root we're in, as that
365 // is the info bubble and will close shortly).
366 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER);
367
368 // We're about to show the bookmark editor. When the bookmark editor closes
369 // we want the browser to become active. NativeWidgetWin::Hide() does a hide
370 // in a such way that activation isn't changed, which means when we close
371 // Windows gets confused as to who it should give active status to. We
372 // explicitly hide the bookmark bubble window in such a way that activation
373 // status changes. That way, when the editor closes, activation is properly
374 // restored to the browser.
375 ShowWindow(GetWidget()->GetNativeView(), SW_HIDE);
376 #elif defined(TOOLKIT_USES_GTK)
377 gfx::NativeWindow parent = GTK_WINDOW(
378 static_cast<views::NativeWidgetGtk*>(GetWidget()->native_widget())->
379 GetTransientParent());
380 #endif
381
382 // Even though we just hid the window, we need to invoke Close to schedule
383 // the delete and all that.
384 Close();
385
386 if (node) {
387 BookmarkEditor::Show(parent, profile_,
388 BookmarkEditor::EditDetails::EditNode(node), 311 BookmarkEditor::EditDetails::EditNode(node),
389 BookmarkEditor::SHOW_TREE); 312 BookmarkEditor::SHOW_TREE);
390 }
391 } 313 }
392 314
393 void BookmarkBubbleView::ApplyEdits() { 315 void BookmarkBubbleView::ApplyEdits() {
394 // Set this to make sure we don't attempt to apply edits again. 316 // Set this to make sure we don't attempt to apply edits again.
395 apply_edits_ = false; 317 apply_edits_ = false;
396 318
397 BookmarkModel* model = profile_->GetBookmarkModel(); 319 BookmarkModel* model = profile_->GetBookmarkModel();
398 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); 320 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
399 if (node) { 321 if (node) {
400 const string16 new_title = title_tf_->text(); 322 const string16 new_title = title_tf_->text();
401 if (new_title != node->GetTitle()) { 323 if (new_title != node->GetTitle()) {
402 model->SetTitle(node, new_title); 324 model->SetTitle(node, new_title);
403 UserMetrics::RecordAction( 325 UserMetrics::RecordAction(
404 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 326 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
405 } 327 }
406 // Last index means 'Choose another folder...' 328 // Last index means 'Choose another folder...'
407 if (parent_combobox_->selected_item() < 329 if (parent_combobox_->selected_item() < parent_model_.GetItemCount() - 1) {
408 parent_model_.GetItemCount() - 1) {
409 const BookmarkNode* new_parent = 330 const BookmarkNode* new_parent =
410 parent_model_.GetNodeAt(parent_combobox_->selected_item()); 331 parent_model_.GetNodeAt(parent_combobox_->selected_item());
411 if (new_parent != node->parent()) { 332 if (new_parent != node->parent()) {
412 UserMetrics::RecordAction( 333 UserMetrics::RecordAction(
413 UserMetricsAction("BookmarkBubble_ChangeParent")); 334 UserMetricsAction("BookmarkBubble_ChangeParent"));
414 model->Move(node, new_parent, new_parent->child_count()); 335 model->Move(node, new_parent, new_parent->child_count());
415 } 336 }
416 } 337 }
417 } 338 }
418 } 339 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698