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