| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/bookmark_bubble_view.h" | 5 #include "chrome/browser/views/bookmark_bubble_view.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/keyboard_codes.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_editor.h" | 12 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 14 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/metrics/user_metrics.h" | 15 #include "chrome/browser/metrics/user_metrics.h" |
| 15 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 16 #include "chrome/browser/views/info_bubble.h" | 17 #include "chrome/browser/views/info_bubble.h" |
| 17 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #include "views/standard_layout.h" | 21 #include "views/standard_layout.h" |
| 21 #include "views/controls/button/native_button.h" | 22 #include "views/controls/button/native_button.h" |
| 22 #include "views/controls/textfield/textfield.h" | 23 #include "views/controls/textfield/textfield.h" |
| 24 #include "views/focus/focus_manager.h" |
| 23 | 25 |
| 24 using views::Combobox; | 26 using views::Combobox; |
| 25 using views::ColumnSet; | 27 using views::ColumnSet; |
| 26 using views::GridLayout; | 28 using views::GridLayout; |
| 27 using views::Label; | 29 using views::Label; |
| 28 using views::Link; | 30 using views::Link; |
| 29 using views::NativeButton; | 31 using views::NativeButton; |
| 30 using views::View; | 32 using views::View; |
| 31 | 33 |
| 32 // Color of the title. | 34 // Color of the title. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 node_parent_index_ = static_cast<int>( | 106 node_parent_index_ = static_cast<int>( |
| 105 find(nodes_.begin(), nodes_.end(), node->GetParent()) - nodes_.begin()); | 107 find(nodes_.begin(), nodes_.end(), node->GetParent()) - nodes_.begin()); |
| 106 } | 108 } |
| 107 | 109 |
| 108 int BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemCount() { | 110 int BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemCount() { |
| 109 return static_cast<int>(nodes_.size() + 1); | 111 return static_cast<int>(nodes_.size() + 1); |
| 110 } | 112 } |
| 111 | 113 |
| 112 std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( | 114 std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( |
| 113 int index) { | 115 int index) { |
| 114 if (index == nodes_.size()) | 116 if (index == static_cast<int>(nodes_.size())) |
| 115 return l10n_util::GetString(IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); | 117 return l10n_util::GetString(IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); |
| 116 return nodes_[index]->GetTitle(); | 118 return nodes_[index]->GetTitle(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 const BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( | 121 const BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( |
| 120 int index) { | 122 int index) { |
| 121 return nodes_[index]; | 123 return nodes_[index]; |
| 122 } | 124 } |
| 123 | 125 |
| 124 void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( | 126 void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 177 } |
| 176 | 178 |
| 177 void BookmarkBubbleView::DidChangeBounds(const gfx::Rect& previous, | 179 void BookmarkBubbleView::DidChangeBounds(const gfx::Rect& previous, |
| 178 const gfx::Rect& current) { | 180 const gfx::Rect& current) { |
| 179 Layout(); | 181 Layout(); |
| 180 } | 182 } |
| 181 | 183 |
| 182 void BookmarkBubbleView::BubbleShown() { | 184 void BookmarkBubbleView::BubbleShown() { |
| 183 DCHECK(GetWidget()); | 185 DCHECK(GetWidget()); |
| 184 GetFocusManager()->RegisterAccelerator( | 186 GetFocusManager()->RegisterAccelerator( |
| 185 views::Accelerator(VK_RETURN, false, false, false), this); | 187 views::Accelerator(base::VKEY_RETURN, false, false, false), this); |
| 186 | 188 |
| 187 title_tf_->RequestFocus(); | 189 title_tf_->RequestFocus(); |
| 188 title_tf_->SelectAll(); | 190 title_tf_->SelectAll(); |
| 189 } | 191 } |
| 190 | 192 |
| 191 bool BookmarkBubbleView::AcceleratorPressed( | 193 bool BookmarkBubbleView::AcceleratorPressed( |
| 192 const views::Accelerator& accelerator) { | 194 const views::Accelerator& accelerator) { |
| 193 if (accelerator.GetKeyCode() != VK_RETURN) | 195 if (accelerator.GetKeyCode() != base::VKEY_RETURN) |
| 194 return false; | 196 return false; |
| 195 if (edit_button_->HasFocus()) | 197 if (edit_button_->HasFocus()) |
| 196 ButtonPressed(edit_button_); | 198 ButtonPressed(edit_button_); |
| 197 else | 199 else |
| 198 ButtonPressed(close_button_); | 200 ButtonPressed(close_button_); |
| 199 return true; | 201 return true; |
| 200 } | 202 } |
| 201 | 203 |
| 204 void BookmarkBubbleView::ViewHierarchyChanged(bool is_add, View* parent, |
| 205 View* child) { |
| 206 if (is_add && child == this) |
| 207 Init(); |
| 208 } |
| 209 |
| 202 BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate, | 210 BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate, |
| 203 Profile* profile, | 211 Profile* profile, |
| 204 const GURL& url, | 212 const GURL& url, |
| 205 bool newly_bookmarked) | 213 bool newly_bookmarked) |
| 206 : delegate_(delegate), | 214 : delegate_(delegate), |
| 207 profile_(profile), | 215 profile_(profile), |
| 208 url_(url), | 216 url_(url), |
| 209 newly_bookmarked_(newly_bookmarked), | 217 newly_bookmarked_(newly_bookmarked), |
| 210 parent_model_( | 218 parent_model_( |
| 211 profile_->GetBookmarkModel(), | 219 profile_->GetBookmarkModel(), |
| 212 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), | 220 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), |
| 213 remove_bookmark_(false), | 221 remove_bookmark_(false), |
| 214 apply_edits_(true) { | 222 apply_edits_(true) { |
| 215 Init(); | |
| 216 } | 223 } |
| 217 | 224 |
| 218 void BookmarkBubbleView::Init() { | 225 void BookmarkBubbleView::Init() { |
| 219 if (!kCloseImage) { | 226 if (!kCloseImage) { |
| 220 kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 227 kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 221 IDR_INFO_BUBBLE_CLOSE); | 228 IDR_INFO_BUBBLE_CLOSE); |
| 222 } | 229 } |
| 223 | 230 |
| 224 remove_link_ = new Link(l10n_util::GetString( | 231 remove_link_ = new Link(l10n_util::GetString( |
| 225 IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK)); | 232 IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK)); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 static_cast<InfoBubble*>(GetWidget())->Close(); | 378 static_cast<InfoBubble*>(GetWidget())->Close(); |
| 372 } | 379 } |
| 373 | 380 |
| 374 void BookmarkBubbleView::ShowEditor() { | 381 void BookmarkBubbleView::ShowEditor() { |
| 375 const BookmarkNode* node = | 382 const BookmarkNode* node = |
| 376 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); | 383 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); |
| 377 | 384 |
| 378 // Commit any edits now. | 385 // Commit any edits now. |
| 379 ApplyEdits(); | 386 ApplyEdits(); |
| 380 | 387 |
| 388 #if defined(OS_WIN) |
| 381 // Parent the editor to our root ancestor (not the root we're in, as that | 389 // Parent the editor to our root ancestor (not the root we're in, as that |
| 382 // is the info bubble and will close shortly). | 390 // is the info bubble and will close shortly). |
| 383 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); | 391 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); |
| 384 | 392 |
| 385 // We're about to show the bookmark editor. When the bookmark editor closes | 393 // We're about to show the bookmark editor. When the bookmark editor closes |
| 386 // we want the browser to become active. WidgetWin::Hide() does a hide in | 394 // we want the browser to become active. WidgetWin::Hide() does a hide in |
| 387 // a such way that activation isn't changed, which means when we close | 395 // a such way that activation isn't changed, which means when we close |
| 388 // Windows gets confused as to who it should give active status to. We | 396 // Windows gets confused as to who it should give active status to. We |
| 389 // explicitly hide the bookmark bubble window in such a way that activation | 397 // explicitly hide the bookmark bubble window in such a way that activation |
| 390 // status changes. That way, when the editor closes, activation is properly | 398 // status changes. That way, when the editor closes, activation is properly |
| 391 // restored to the browser. | 399 // restored to the browser. |
| 392 ShowWindow(GetWidget()->GetNativeView(), SW_HIDE); | 400 ShowWindow(GetWidget()->GetNativeView(), SW_HIDE); |
| 401 #else |
| 402 NOTIMPLEMENTED(); // TODO(brettw) find the parent. |
| 403 gfx::NativeView parent = NULL; |
| 404 #endif |
| 393 | 405 |
| 394 // Even though we just hid the window, we need to invoke Close to schedule | 406 // Even though we just hid the window, we need to invoke Close to schedule |
| 395 // the delete and all that. | 407 // the delete and all that. |
| 396 Close(); | 408 Close(); |
| 397 | 409 |
| 398 if (node) { | 410 if (node) { |
| 399 BookmarkEditor::Show(parent, profile_, NULL, node, | 411 BookmarkEditor::Show(parent, profile_, NULL, node, |
| 400 BookmarkEditor::SHOW_TREE, NULL); | 412 BookmarkEditor::SHOW_TREE, NULL); |
| 401 } | 413 } |
| 402 } | 414 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 419 parent_model_.GetItemCount() - 1) { | 431 parent_model_.GetItemCount() - 1) { |
| 420 const BookmarkNode* new_parent = | 432 const BookmarkNode* new_parent = |
| 421 parent_model_.GetNodeAt(parent_combobox_->selected_item()); | 433 parent_model_.GetNodeAt(parent_combobox_->selected_item()); |
| 422 if (new_parent != node->GetParent()) { | 434 if (new_parent != node->GetParent()) { |
| 423 UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); | 435 UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); |
| 424 model->Move(node, new_parent, new_parent->GetChildCount()); | 436 model->Move(node, new_parent, new_parent->GetChildCount()); |
| 425 } | 437 } |
| 426 } | 438 } |
| 427 } | 439 } |
| 428 } | 440 } |
| OLD | NEW |