OLD | NEW |
---|---|
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)); |
95 | |
96 bookmark_bubble_->title_tf_->RequestFocus(); | |
Ben Goodger (Google)
2011/11/08 23:58:10
Can the title_tf_ be the InitiallyFocusedView inst
msw
2011/11/09 01:47:05
Done.
| |
97 bookmark_bubble_->title_tf_->SelectAll(); | |
Ben Goodger (Google)
2011/11/08 23:58:10
I wonder if we should have a property on TextField
msw
2011/11/09 01:47:05
Done.
| |
111 } | 98 } |
112 | 99 |
113 // static | 100 // static |
114 bool BookmarkBubbleView::IsShowing() { | 101 bool BookmarkBubbleView::IsShowing() { |
115 return bookmark_bubble_ != NULL; | 102 return bookmark_bubble_ != NULL; |
116 } | 103 } |
117 | 104 |
118 void BookmarkBubbleView::Hide() { | 105 void BookmarkBubbleView::Hide() { |
119 if (IsShowing()) | 106 if (IsShowing()) |
120 bookmark_bubble_->Close(); | 107 bookmark_bubble_->GetWidget()->Close(); |
121 } | 108 } |
122 | 109 |
123 BookmarkBubbleView::~BookmarkBubbleView() { | 110 BookmarkBubbleView::~BookmarkBubbleView() { |
124 if (apply_edits_) { | 111 if (apply_edits_) { |
125 ApplyEdits(); | 112 ApplyEdits(); |
126 } else if (remove_bookmark_) { | 113 } else if (remove_bookmark_) { |
127 BookmarkModel* model = profile_->GetBookmarkModel(); | 114 BookmarkModel* model = profile_->GetBookmarkModel(); |
128 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); | 115 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); |
129 if (node) | 116 if (node) |
130 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); | 117 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); |
131 } | 118 } |
132 } | 119 } |
133 | 120 |
134 void BookmarkBubbleView::BubbleShown() { | 121 void BookmarkBubbleView::WindowClosing() { |
135 DCHECK(GetWidget()); | 122 // We have to reset |bubble_| here, not in our destructor, because we'll be |
136 GetFocusManager()->RegisterAccelerator( | 123 // destroyed asynchronously and the shown state will be checked before then. |
137 views::Accelerator(ui::VKEY_RETURN, false, false, false), this); | 124 DCHECK(bookmark_bubble_ == this); |
125 bookmark_bubble_ = NULL; | |
138 | 126 |
139 title_tf_->RequestFocus(); | 127 content::NotificationService::current()->Notify( |
140 title_tf_->SelectAll(); | 128 chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN, |
141 } | 129 content::Source<Profile>(profile_->GetOriginalProfile()), |
130 content::NotificationService::NoDetails()); | |
131 } | |
142 | 132 |
143 bool BookmarkBubbleView::AcceleratorPressed( | 133 bool BookmarkBubbleView::AcceleratorPressed( |
144 const views::Accelerator& accelerator) { | 134 const views::Accelerator& accelerator) { |
145 if (accelerator.key_code() != ui::VKEY_RETURN) | 135 if (accelerator.key_code() == ui::VKEY_RETURN) { |
146 return false; | 136 if (edit_button_->HasFocus()) |
137 HandleButtonPressed(edit_button_); | |
138 else | |
139 HandleButtonPressed(close_button_); | |
140 return true; | |
141 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { | |
142 remove_bookmark_ = newly_bookmarked_; | |
143 apply_edits_ = false; | |
144 } | |
147 | 145 |
148 if (edit_button_->HasFocus()) | 146 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 } | 147 } |
176 | 148 |
177 void BookmarkBubbleView::Init() { | 149 void BookmarkBubbleView::Init() { |
178 remove_link_ = new views::Link(l10n_util::GetStringUTF16( | 150 remove_link_ = new views::Link(l10n_util::GetStringUTF16( |
179 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | 151 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); |
180 remove_link_->set_listener(this); | 152 remove_link_->set_listener(this); |
181 remove_link_->SetBackgroundColor(Bubble::kBackgroundColor); | |
182 | 153 |
183 edit_button_ = new views::NativeTextButton( | 154 edit_button_ = new views::NativeTextButton( |
184 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 155 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); |
185 | 156 |
186 close_button_ = new views::NativeTextButton( | 157 close_button_ = new views::NativeTextButton( |
187 this, l10n_util::GetStringUTF16(IDS_DONE)); | 158 this, l10n_util::GetStringUTF16(IDS_DONE)); |
188 close_button_->SetIsDefault(true); | 159 close_button_->SetIsDefault(true); |
189 | 160 |
190 views::Label* combobox_label = new views::Label( | 161 views::Label* combobox_label = new views::Label( |
191 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 162 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
192 combobox_label->SetBackgroundColor(Bubble::kBackgroundColor); | |
193 | 163 |
194 parent_combobox_ = new views::Combobox(&parent_model_); | 164 parent_combobox_ = new views::Combobox(&parent_model_); |
195 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); | 165 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); |
196 parent_combobox_->set_listener(this); | 166 parent_combobox_->set_listener(this); |
197 parent_combobox_->SetAccessibleName(combobox_label->GetText()); | 167 parent_combobox_->SetAccessibleName(combobox_label->GetText()); |
198 | 168 |
199 views::Label* title_label = new views::Label( | 169 views::Label* title_label = new views::Label( |
200 l10n_util::GetStringUTF16( | 170 l10n_util::GetStringUTF16( |
201 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : | 171 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : |
202 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); | 172 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); |
203 title_label->SetFont( | 173 title_label->SetFont( |
204 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); | 174 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); |
205 title_label->SetBackgroundColor(Bubble::kBackgroundColor); | |
206 title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117)); | 175 title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117)); |
207 | 176 |
208 GridLayout* layout = new GridLayout(this); | 177 GridLayout* layout = new GridLayout(this); |
209 SetLayoutManager(layout); | 178 SetLayoutManager(layout); |
210 | 179 |
211 ColumnSet* cs = layout->AddColumnSet(0); | 180 ColumnSet* cs = layout->AddColumnSet(0); |
212 | 181 |
213 // Top (title) row. | 182 // Top (title) row. |
214 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 183 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
215 0, 0); | 184 0, 0); |
(...skipping 22 matching lines...) Expand all Loading... | |
238 GridLayout::USE_PREF, 0, 0); | 207 GridLayout::USE_PREF, 0, 0); |
239 | 208 |
240 layout->StartRow(0, 0); | 209 layout->StartRow(0, 0); |
241 layout->AddView(title_label); | 210 layout->AddView(title_label); |
242 layout->AddView(remove_link_); | 211 layout->AddView(remove_link_); |
243 | 212 |
244 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 213 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
245 layout->StartRow(0, 2); | 214 layout->StartRow(0, 2); |
246 views::Label* label = new views::Label( | 215 views::Label* label = new views::Label( |
247 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 216 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
248 label->SetBackgroundColor(Bubble::kBackgroundColor); | |
249 layout->AddView(label); | 217 layout->AddView(label); |
250 title_tf_ = new views::Textfield(); | 218 title_tf_ = new views::Textfield(); |
251 title_tf_->SetText(GetTitle()); | 219 title_tf_->SetText(GetTitle()); |
252 layout->AddView(title_tf_); | 220 layout->AddView(title_tf_); |
253 | 221 |
254 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 222 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
255 | 223 |
256 layout->StartRow(0, 2); | 224 layout->StartRow(0, 2); |
257 layout->AddView(combobox_label); | 225 layout->AddView(combobox_label); |
258 layout->AddView(parent_combobox_); | 226 layout->AddView(parent_combobox_); |
259 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 227 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
260 | 228 |
261 layout->StartRow(0, 3); | 229 layout->StartRow(0, 3); |
262 layout->AddView(edit_button_); | 230 layout->AddView(edit_button_); |
263 layout->AddView(close_button_); | 231 layout->AddView(close_button_); |
232 | |
233 AddAccelerator(views::Accelerator(ui::VKEY_RETURN, 0)); | |
234 } | |
235 | |
236 BookmarkBubbleView::BookmarkBubbleView(views::Widget* parent, | |
237 const gfx::Point& anchor, | |
238 Profile* profile, | |
239 const GURL& url, | |
240 bool newly_bookmarked) | |
241 : BubbleDelegateView(anchor, views::BubbleBorder::TOP_RIGHT, kColor), | |
242 parent_(parent), | |
243 profile_(profile), | |
244 url_(url), | |
245 newly_bookmarked_(newly_bookmarked), | |
246 parent_model_( | |
247 profile_->GetBookmarkModel(), | |
248 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), | |
249 remove_bookmark_(false), | |
250 apply_edits_(true) { | |
264 } | 251 } |
265 | 252 |
266 string16 BookmarkBubbleView::GetTitle() { | 253 string16 BookmarkBubbleView::GetTitle() { |
267 BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); | 254 BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); |
268 const BookmarkNode* node = | 255 const BookmarkNode* node = |
269 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | 256 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
270 if (node) | 257 if (node) |
271 return node->GetTitle(); | 258 return node->GetTitle(); |
272 else | 259 else |
273 NOTREACHED(); | 260 NOTREACHED(); |
274 return string16(); | 261 return string16(); |
275 } | 262 } |
276 | 263 |
277 void BookmarkBubbleView::ButtonPressed( | 264 void BookmarkBubbleView::ButtonPressed( |
278 views::Button* sender, const views::Event& event) { | 265 views::Button* sender, const views::Event& event) { |
279 HandleButtonPressed(sender); | 266 HandleButtonPressed(sender); |
280 } | 267 } |
281 | 268 |
282 void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) { | 269 void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) { |
283 DCHECK(source == remove_link_); | 270 DCHECK(source == remove_link_); |
284 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | 271 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); |
285 | 272 |
286 // Set this so we remove the bookmark after the window closes. | 273 // Set this so we remove the bookmark after the window closes. |
287 remove_bookmark_ = true; | 274 remove_bookmark_ = true; |
288 apply_edits_ = false; | 275 apply_edits_ = false; |
289 | 276 StartFade(false); |
290 bubble_->set_fade_away_on_close(true); | |
291 Close(); | |
292 } | 277 } |
293 | 278 |
294 void BookmarkBubbleView::ItemChanged(views::Combobox* combobox, | 279 void BookmarkBubbleView::ItemChanged(views::Combobox* combobox, |
295 int prev_index, | 280 int prev_index, |
296 int new_index) { | 281 int new_index) { |
297 if (new_index + 1 == parent_model_.GetItemCount()) { | 282 if (new_index + 1 == parent_model_.GetItemCount()) { |
298 UserMetrics::RecordAction( | 283 UserMetrics::RecordAction( |
299 UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 284 UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
300 | |
301 ShowEditor(); | 285 ShowEditor(); |
302 return; | |
303 } | 286 } |
304 } | 287 } |
305 | 288 |
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) { | 289 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
344 if (sender == edit_button_) { | 290 if (sender == edit_button_) { |
345 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 291 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
346 bubble_->set_fade_away_on_close(true); | |
347 ShowEditor(); | 292 ShowEditor(); |
348 } else { | 293 } else { |
349 DCHECK(sender == close_button_); | 294 DCHECK_EQ(sender, close_button_); |
350 bubble_->set_fade_away_on_close(true); | 295 StartFade(false); |
351 Close(); | |
352 } | 296 } |
353 // WARNING: we've most likely been deleted when CloseWindow returns. | |
354 } | 297 } |
355 | 298 |
356 void BookmarkBubbleView::ShowEditor() { | 299 void BookmarkBubbleView::ShowEditor() { |
357 const BookmarkNode* node = | 300 const BookmarkNode* node = |
358 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); | 301 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); |
302 views::Widget* parent = parent_; | |
303 Profile* profile = profile_; | |
304 ApplyEdits(); | |
305 GetWidget()->Close(); | |
359 | 306 |
360 #if defined(USE_AURA) | 307 if (node) |
361 NOTIMPLEMENTED(); | 308 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), | 309 BookmarkEditor::EditDetails::EditNode(node), |
389 BookmarkEditor::SHOW_TREE); | 310 BookmarkEditor::SHOW_TREE); |
390 } | |
391 } | 311 } |
392 | 312 |
393 void BookmarkBubbleView::ApplyEdits() { | 313 void BookmarkBubbleView::ApplyEdits() { |
394 // Set this to make sure we don't attempt to apply edits again. | 314 // Set this to make sure we don't attempt to apply edits again. |
395 apply_edits_ = false; | 315 apply_edits_ = false; |
396 | 316 |
397 BookmarkModel* model = profile_->GetBookmarkModel(); | 317 BookmarkModel* model = profile_->GetBookmarkModel(); |
398 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); | 318 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); |
399 if (node) { | 319 if (node) { |
400 const string16 new_title = title_tf_->text(); | 320 const string16 new_title = title_tf_->text(); |
401 if (new_title != node->GetTitle()) { | 321 if (new_title != node->GetTitle()) { |
402 model->SetTitle(node, new_title); | 322 model->SetTitle(node, new_title); |
403 UserMetrics::RecordAction( | 323 UserMetrics::RecordAction( |
404 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 324 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
405 } | 325 } |
406 // Last index means 'Choose another folder...' | 326 // Last index means 'Choose another folder...' |
407 if (parent_combobox_->selected_item() < | 327 if (parent_combobox_->selected_item() < parent_model_.GetItemCount() - 1) { |
408 parent_model_.GetItemCount() - 1) { | |
409 const BookmarkNode* new_parent = | 328 const BookmarkNode* new_parent = |
410 parent_model_.GetNodeAt(parent_combobox_->selected_item()); | 329 parent_model_.GetNodeAt(parent_combobox_->selected_item()); |
411 if (new_parent != node->parent()) { | 330 if (new_parent != node->parent()) { |
412 UserMetrics::RecordAction( | 331 UserMetrics::RecordAction( |
413 UserMetricsAction("BookmarkBubble_ChangeParent")); | 332 UserMetricsAction("BookmarkBubble_ChangeParent")); |
414 model->Move(node, new_parent, new_parent->child_count()); | 333 model->Move(node, new_parent, new_parent->child_count()); |
415 } | 334 } |
416 } | 335 } |
417 } | 336 } |
418 } | 337 } |
OLD | NEW |