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 "chrome/app/chrome_dll_resource.h" | 7 #include "chrome/app/chrome_dll_resource.h" |
8 #include "chrome/app/theme/theme_resources.h" | 8 #include "chrome/app/theme/theme_resources.h" |
9 #include "chrome/browser/bookmarks/bookmark_bar_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/standard_layout.h" | 11 #include "chrome/browser/standard_layout.h" |
12 #include "chrome/browser/user_metrics.h" | 12 #include "chrome/browser/user_metrics.h" |
13 #include "chrome/browser/views/bookmark_editor_view.h" | 13 #include "chrome/browser/views/bookmark_editor_view.h" |
14 #include "chrome/browser/views/info_bubble.h" | 14 #include "chrome/browser/views/info_bubble.h" |
15 #include "chrome/common/gfx/chrome_canvas.h" | 15 #include "chrome/common/gfx/chrome_canvas.h" |
16 #include "chrome/common/l10n_util.h" | 16 #include "chrome/common/l10n_util.h" |
17 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
18 #include "chrome/common/resource_bundle.h" | 18 #include "chrome/common/resource_bundle.h" |
19 #include "chrome/views/button.h" | 19 #include "chrome/views/button.h" |
(...skipping 24 matching lines...) Expand all Loading... |
44 | 44 |
45 // Max number of most recently used folders. | 45 // Max number of most recently used folders. |
46 static const size_t kMaxMRUFolders = 5; | 46 static const size_t kMaxMRUFolders = 5; |
47 | 47 |
48 // Bubble close image. | 48 // Bubble close image. |
49 static SkBitmap* kCloseImage = NULL; | 49 static SkBitmap* kCloseImage = NULL; |
50 | 50 |
51 // RecentlyUsedFoldersModel --------------------------------------------------- | 51 // RecentlyUsedFoldersModel --------------------------------------------------- |
52 | 52 |
53 BookmarkBubbleView::RecentlyUsedFoldersModel::RecentlyUsedFoldersModel( | 53 BookmarkBubbleView::RecentlyUsedFoldersModel::RecentlyUsedFoldersModel( |
54 BookmarkBarModel* bb_model, BookmarkBarNode* node) | 54 BookmarkModel* bb_model, BookmarkNode* node) |
55 // Use + 2 to account for bookmark bar and other node. | 55 // Use + 2 to account for bookmark bar and other node. |
56 : nodes_(bb_model->GetMostRecentlyModifiedGroups(kMaxMRUFolders + 2)), | 56 : nodes_(bb_model->GetMostRecentlyModifiedGroups(kMaxMRUFolders + 2)), |
57 node_parent_index_(0) { | 57 node_parent_index_(0) { |
58 // TODO(sky): bug 1173415 add a separator in the combobox here. | 58 // TODO(sky): bug 1173415 add a separator in the combobox here. |
59 | 59 |
60 // We special case the placement of these, so remove them from the list, then | 60 // We special case the placement of these, so remove them from the list, then |
61 // fix up the order. | 61 // fix up the order. |
62 RemoveNode(bb_model->GetBookmarkBarNode()); | 62 RemoveNode(bb_model->GetBookmarkBarNode()); |
63 RemoveNode(bb_model->other_node()); | 63 RemoveNode(bb_model->other_node()); |
64 RemoveNode(node->GetParent()); | 64 RemoveNode(node->GetParent()); |
(...skipping 21 matching lines...) Expand all Loading... |
86 return static_cast<int>(nodes_.size() + 1); | 86 return static_cast<int>(nodes_.size() + 1); |
87 } | 87 } |
88 | 88 |
89 std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( | 89 std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( |
90 ComboBox* source, int index) { | 90 ComboBox* source, int index) { |
91 if (index == nodes_.size()) | 91 if (index == nodes_.size()) |
92 return l10n_util::GetString(IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); | 92 return l10n_util::GetString(IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); |
93 return nodes_[index]->GetTitle(); | 93 return nodes_[index]->GetTitle(); |
94 } | 94 } |
95 | 95 |
96 BookmarkBarNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( | 96 BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( |
97 int index) { | 97 int index) { |
98 return nodes_[index]; | 98 return nodes_[index]; |
99 } | 99 } |
100 | 100 |
101 void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( | 101 void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( |
102 BookmarkBarNode* node) { | 102 BookmarkNode* node) { |
103 std::vector<BookmarkBarNode*>::iterator i = | 103 std::vector<BookmarkNode*>::iterator i = |
104 find(nodes_.begin(), nodes_.end(), node); | 104 find(nodes_.begin(), nodes_.end(), node); |
105 if (i != nodes_.end()) | 105 if (i != nodes_.end()) |
106 nodes_.erase(i); | 106 nodes_.erase(i); |
107 } | 107 } |
108 | 108 |
109 // BookmarkBubbleView --------------------------------------------------------- | 109 // BookmarkBubbleView --------------------------------------------------------- |
110 | 110 |
111 // static | 111 // static |
112 void BookmarkBubbleView::Show(HWND parent, | 112 void BookmarkBubbleView::Show(HWND parent, |
113 const gfx::Rect& bounds, | 113 const gfx::Rect& bounds, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate, | 158 BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate, |
159 Profile* profile, | 159 Profile* profile, |
160 const GURL& url, | 160 const GURL& url, |
161 bool newly_bookmarked) | 161 bool newly_bookmarked) |
162 : delegate_(delegate), | 162 : delegate_(delegate), |
163 profile_(profile), | 163 profile_(profile), |
164 url_(url), | 164 url_(url), |
165 newly_bookmarked_(newly_bookmarked), | 165 newly_bookmarked_(newly_bookmarked), |
166 parent_model_(profile_->GetBookmarkBarModel(), | 166 parent_model_(profile_->GetBookmarkModel(), |
167 profile_->GetBookmarkBarModel()->GetNodeByURL(url)) { | 167 profile_->GetBookmarkModel()->GetNodeByURL(url)) { |
168 Init(); | 168 Init(); |
169 } | 169 } |
170 | 170 |
171 void BookmarkBubbleView::Init() { | 171 void BookmarkBubbleView::Init() { |
172 if (!kCloseImage) { | 172 if (!kCloseImage) { |
173 kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 173 kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
174 IDR_INFO_BUBBLE_CLOSE); | 174 IDR_INFO_BUBBLE_CLOSE); |
175 } | 175 } |
176 | 176 |
177 remove_link_ = new Link(l10n_util::GetString( | 177 remove_link_ = new Link(l10n_util::GetString( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 new Label(l10n_util::GetString(IDS_BOOMARK_BUBBLE_FOLDER_TEXT))); | 247 new Label(l10n_util::GetString(IDS_BOOMARK_BUBBLE_FOLDER_TEXT))); |
248 layout->AddView(parent_combobox_); | 248 layout->AddView(parent_combobox_); |
249 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 249 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
250 | 250 |
251 layout->StartRow(0, 3); | 251 layout->StartRow(0, 3); |
252 layout->AddView(edit_button_); | 252 layout->AddView(edit_button_); |
253 layout->AddView(close_button_); | 253 layout->AddView(close_button_); |
254 } | 254 } |
255 | 255 |
256 std::wstring BookmarkBubbleView::GetTitle() { | 256 std::wstring BookmarkBubbleView::GetTitle() { |
257 BookmarkBarModel* bookmark_model= profile_->GetBookmarkBarModel(); | 257 BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); |
258 BookmarkBarNode* node = bookmark_model->GetNodeByURL(url_); | 258 BookmarkNode* node = bookmark_model->GetNodeByURL(url_); |
259 if (node) | 259 if (node) |
260 return node->GetTitle(); | 260 return node->GetTitle(); |
261 else | 261 else |
262 NOTREACHED(); | 262 NOTREACHED(); |
263 return std::wstring(); | 263 return std::wstring(); |
264 } | 264 } |
265 | 265 |
266 void BookmarkBubbleView::ButtonPressed(ChromeViews::NativeButton* sender) {
| 266 void BookmarkBubbleView::ButtonPressed(ChromeViews::NativeButton* sender) {
|
267 if (sender == edit_button_) { | 267 if (sender == edit_button_) { |
268 UserMetrics::RecordAction(L"BookmarkBubble_Edit", profile_); | 268 UserMetrics::RecordAction(L"BookmarkBubble_Edit", profile_); |
(...skipping 12 matching lines...) Expand all Loading... |
281 | 281 |
282 void BookmarkBubbleView::ItemChanged(ComboBox* combo_box, | 282 void BookmarkBubbleView::ItemChanged(ComboBox* combo_box, |
283 int prev_index, | 283 int prev_index, |
284 int new_index) { | 284 int new_index) { |
285 if (new_index + 1 == parent_model_.GetItemCount(parent_combobox_)) { | 285 if (new_index + 1 == parent_model_.GetItemCount(parent_combobox_)) { |
286 UserMetrics::RecordAction(L"BookmarkBubble_EditFromCombobox", profile_); | 286 UserMetrics::RecordAction(L"BookmarkBubble_EditFromCombobox", profile_); |
287 | 287 |
288 ShowEditor(); | 288 ShowEditor(); |
289 return; | 289 return; |
290 } | 290 } |
291 BookmarkBarModel* model = profile_->GetBookmarkBarModel(); | 291 BookmarkModel* model = profile_->GetBookmarkModel(); |
292 BookmarkBarNode* node = model->GetNodeByURL(url_); | 292 BookmarkNode* node = model->GetNodeByURL(url_); |
293 if (node) { | 293 if (node) { |
294 BookmarkBarNode* new_parent = parent_model_.GetNodeAt(new_index); | 294 BookmarkNode* new_parent = parent_model_.GetNodeAt(new_index); |
295 if (new_parent != node->GetParent()) { | 295 if (new_parent != node->GetParent()) { |
296 UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); | 296 UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); |
297 model->Move(node, new_parent, new_parent->GetChildCount()); | 297 model->Move(node, new_parent, new_parent->GetChildCount()); |
298 } | 298 } |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 void BookmarkBubbleView::InfoBubbleClosing(InfoBubble* info_bubble) { | 302 void BookmarkBubbleView::InfoBubbleClosing(InfoBubble* info_bubble) { |
303 if (delegate_) | 303 if (delegate_) |
304 delegate_->InfoBubbleClosing(info_bubble); | 304 delegate_->InfoBubbleClosing(info_bubble); |
305 NotificationService::current()->Notify( | 305 NotificationService::current()->Notify( |
306 NOTIFY_BOOKMARK_BUBBLE_HIDDEN, | 306 NOTIFY_BOOKMARK_BUBBLE_HIDDEN, |
307 Source<Profile>(profile_->GetOriginalProfile()), | 307 Source<Profile>(profile_->GetOriginalProfile()), |
308 NotificationService::NoDetails()); | 308 NotificationService::NoDetails()); |
309 } | 309 } |
310 | 310 |
311 bool BookmarkBubbleView::CloseOnEscape() { | 311 bool BookmarkBubbleView::CloseOnEscape() { |
312 return delegate_ ? delegate_->CloseOnEscape() : true; | 312 return delegate_ ? delegate_->CloseOnEscape() : true; |
313 } | 313 } |
314 | 314 |
315 void BookmarkBubbleView::Close() { | 315 void BookmarkBubbleView::Close() { |
316 static_cast<InfoBubble*>(GetViewContainer())->Close(); | 316 static_cast<InfoBubble*>(GetViewContainer())->Close(); |
317 } | 317 } |
318 | 318 |
319 void BookmarkBubbleView::RemoveBookmark() { | 319 void BookmarkBubbleView::RemoveBookmark() { |
320 UserMetrics::RecordAction(L"BookmarkBubble_Unstar", profile_); | 320 UserMetrics::RecordAction(L"BookmarkBubble_Unstar", profile_); |
321 | 321 |
322 GURL url = url_; | 322 GURL url = url_; |
323 BookmarkBarModel* model = profile_->GetBookmarkBarModel(); | 323 BookmarkModel* model = profile_->GetBookmarkModel(); |
324 // Close first, then notify the service. That way we know we won't be | 324 // Close first, then notify the service. That way we know we won't be |
325 // visible and don't have to worry about some other window becoming | 325 // visible and don't have to worry about some other window becoming |
326 // activated and deleting us before we invoke Close. | 326 // activated and deleting us before we invoke Close. |
327 Close(); | 327 Close(); |
328 // WARNING: we've likely been deleted. | 328 // WARNING: we've likely been deleted. |
329 if (model) | 329 if (model) |
330 model->SetURLStarred(url, std::wstring(), false); | 330 model->SetURLStarred(url, std::wstring(), false); |
331 } | 331 } |
332 | 332 |
333 void BookmarkBubbleView::ShowEditor() { | 333 void BookmarkBubbleView::ShowEditor() { |
(...skipping 11 matching lines...) Expand all Loading... |
345 ShowWindow(GetViewContainer()->GetHWND(), SW_HIDE); | 345 ShowWindow(GetViewContainer()->GetHWND(), SW_HIDE); |
346 | 346 |
347 // Even though we just hid the window, we need to invoke Close to schedule | 347 // Even though we just hid the window, we need to invoke Close to schedule |
348 // the delete and all that. | 348 // the delete and all that. |
349 Close(); | 349 Close(); |
350 | 350 |
351 BookmarkEditorView::Show(parent, profile_, url_, title_); | 351 BookmarkEditorView::Show(parent, profile_, url_, title_); |
352 } | 352 } |
353 | 353 |
354 void BookmarkBubbleView::SetNodeTitleFromTextField() { | 354 void BookmarkBubbleView::SetNodeTitleFromTextField() { |
355 BookmarkBarModel* model = profile_->GetBookmarkBarModel(); | 355 BookmarkModel* model = profile_->GetBookmarkModel(); |
356 BookmarkBarNode* node = model->GetNodeByURL(url_); | 356 BookmarkNode* node = model->GetNodeByURL(url_); |
357 if (node) { | 357 if (node) { |
358 const std::wstring new_title = title_tf_->GetText(); | 358 const std::wstring new_title = title_tf_->GetText(); |
359 if (new_title != node->GetTitle()) { | 359 if (new_title != node->GetTitle()) { |
360 model->SetTitle(node, new_title); | 360 model->SetTitle(node, new_title); |
361 UserMetrics::RecordAction(L"BookmarkBubble_ChangeTitleInBubble", | 361 UserMetrics::RecordAction(L"BookmarkBubble_ChangeTitleInBubble", |
362 profile_); | 362 profile_); |
363 } | 363 } |
364 } | 364 } |
365 } | 365 } |
OLD | NEW |