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" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 void BookmarkBubbleView::Hide() { | 82 void BookmarkBubbleView::Hide() { |
83 if (IsShowing()) | 83 if (IsShowing()) |
84 bookmark_bubble_->GetWidget()->Close(); | 84 bookmark_bubble_->GetWidget()->Close(); |
85 } | 85 } |
86 | 86 |
87 BookmarkBubbleView::~BookmarkBubbleView() { | 87 BookmarkBubbleView::~BookmarkBubbleView() { |
88 if (apply_edits_) { | 88 if (apply_edits_) { |
89 ApplyEdits(); | 89 ApplyEdits(); |
90 } else if (remove_bookmark_) { | 90 } else if (remove_bookmark_) { |
91 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); | 91 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
92 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); | 92 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); |
93 if (node) | 93 if (node) |
94 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); | 94 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); |
95 } | 95 } |
96 // |parent_combobox_| needs to be destroyed before |parent_model_| as it | 96 // |parent_combobox_| needs to be destroyed before |parent_model_| as it |
97 // uses |parent_model_| in its destructor. | 97 // uses |parent_model_| in its destructor. |
98 delete parent_combobox_; | 98 delete parent_combobox_; |
99 } | 99 } |
100 | 100 |
101 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 101 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
102 return title_tf_; | 102 return title_tf_; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 bool newly_bookmarked) | 251 bool newly_bookmarked) |
252 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 252 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
253 observer_(observer), | 253 observer_(observer), |
254 delegate_(delegate.Pass()), | 254 delegate_(delegate.Pass()), |
255 profile_(profile), | 255 profile_(profile), |
256 url_(url), | 256 url_(url), |
257 newly_bookmarked_(newly_bookmarked), | 257 newly_bookmarked_(newly_bookmarked), |
258 parent_model_( | 258 parent_model_( |
259 BookmarkModelFactory::GetForProfile(profile_), | 259 BookmarkModelFactory::GetForProfile(profile_), |
260 BookmarkModelFactory::GetForProfile(profile_)-> | 260 BookmarkModelFactory::GetForProfile(profile_)-> |
261 GetMostRecentlyAddedUserNodeForURL(url)), | 261 GetMostRecentlyAddedNodeForURL(url)), |
262 remove_button_(NULL), | 262 remove_button_(NULL), |
263 edit_button_(NULL), | 263 edit_button_(NULL), |
264 close_button_(NULL), | 264 close_button_(NULL), |
265 title_tf_(NULL), | 265 title_tf_(NULL), |
266 parent_combobox_(NULL), | 266 parent_combobox_(NULL), |
267 sync_promo_view_(NULL), | 267 sync_promo_view_(NULL), |
268 remove_bookmark_(false), | 268 remove_bookmark_(false), |
269 apply_edits_(true) { | 269 apply_edits_(true) { |
270 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); | 270 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); |
271 // Compensate for built-in vertical padding in the anchor view's image. | 271 // Compensate for built-in vertical padding in the anchor view's image. |
272 set_anchor_view_insets(gfx::Insets(2, 0, 2, 0)); | 272 set_anchor_view_insets(gfx::Insets(2, 0, 2, 0)); |
273 } | 273 } |
274 | 274 |
275 base::string16 BookmarkBubbleView::GetTitle() { | 275 base::string16 BookmarkBubbleView::GetTitle() { |
276 BookmarkModel* bookmark_model = | 276 BookmarkModel* bookmark_model = |
277 BookmarkModelFactory::GetForProfile(profile_); | 277 BookmarkModelFactory::GetForProfile(profile_); |
278 const BookmarkNode* node = | 278 const BookmarkNode* node = |
279 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); | 279 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
280 if (node) | 280 if (node) |
281 return node->GetTitle(); | 281 return node->GetTitle(); |
282 else | 282 else |
283 NOTREACHED(); | 283 NOTREACHED(); |
284 return base::string16(); | 284 return base::string16(); |
285 } | 285 } |
286 | 286 |
287 gfx::Size BookmarkBubbleView::GetMinimumSize() const { | 287 gfx::Size BookmarkBubbleView::GetMinimumSize() const { |
288 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); | 288 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); |
289 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); | 289 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 321 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
322 ShowEditor(); | 322 ShowEditor(); |
323 } else { | 323 } else { |
324 DCHECK_EQ(close_button_, sender); | 324 DCHECK_EQ(close_button_, sender); |
325 GetWidget()->Close(); | 325 GetWidget()->Close(); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 void BookmarkBubbleView::ShowEditor() { | 329 void BookmarkBubbleView::ShowEditor() { |
330 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 330 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
331 profile_)->GetMostRecentlyAddedUserNodeForURL(url_); | 331 profile_)->GetMostRecentlyAddedNodeForURL(url_); |
332 views::Widget* parent = anchor_widget(); | 332 views::Widget* parent = anchor_widget(); |
333 DCHECK(parent); | 333 DCHECK(parent); |
334 | 334 |
335 Profile* profile = profile_; | 335 Profile* profile = profile_; |
336 ApplyEdits(); | 336 ApplyEdits(); |
337 GetWidget()->Close(); | 337 GetWidget()->Close(); |
338 | 338 |
339 if (node && parent) | 339 if (node && parent) |
340 BookmarkEditor::Show(parent->GetNativeWindow(), profile, | 340 BookmarkEditor::Show(parent->GetNativeWindow(), profile, |
341 BookmarkEditor::EditDetails::EditNode(node), | 341 BookmarkEditor::EditDetails::EditNode(node), |
342 BookmarkEditor::SHOW_TREE); | 342 BookmarkEditor::SHOW_TREE); |
343 } | 343 } |
344 | 344 |
345 void BookmarkBubbleView::ApplyEdits() { | 345 void BookmarkBubbleView::ApplyEdits() { |
346 // Set this to make sure we don't attempt to apply edits again. | 346 // Set this to make sure we don't attempt to apply edits again. |
347 apply_edits_ = false; | 347 apply_edits_ = false; |
348 | 348 |
349 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); | 349 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
350 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); | 350 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); |
351 if (node) { | 351 if (node) { |
352 const base::string16 new_title = title_tf_->text(); | 352 const base::string16 new_title = title_tf_->text(); |
353 if (new_title != node->GetTitle()) { | 353 if (new_title != node->GetTitle()) { |
354 model->SetTitle(node, new_title); | 354 model->SetTitle(node, new_title); |
355 content::RecordAction( | 355 content::RecordAction( |
356 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 356 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
357 } | 357 } |
358 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 358 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
359 } | 359 } |
360 } | 360 } |
OLD | NEW |