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" | 17 #include "chrome/browser/ui/views/bubble/bubble.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "content/browser/user_metrics.h" | 19 #include "content/browser/user_metrics.h" |
20 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
23 #include "ui/base/keycodes/keyboard_codes.h" | 23 #include "ui/base/keycodes/keyboard_codes.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/color_utils.h" | |
28 #include "views/controls/button/text_button.h" | 27 #include "views/controls/button/text_button.h" |
29 #include "views/controls/label.h" | 28 #include "views/controls/label.h" |
30 #include "views/controls/link.h" | 29 #include "views/controls/link.h" |
31 #include "views/controls/textfield/textfield.h" | 30 #include "views/controls/textfield/textfield.h" |
32 #include "views/events/event.h" | 31 #include "views/events/event.h" |
33 #include "views/focus/focus_manager.h" | 32 #include "views/focus/focus_manager.h" |
34 #include "views/layout/grid_layout.h" | 33 #include "views/layout/grid_layout.h" |
35 #include "views/layout/layout_constants.h" | 34 #include "views/layout/layout_constants.h" |
36 #include "views/window/client_view.h" | 35 #include "views/window/client_view.h" |
37 | 36 |
38 #if defined(TOOLKIT_USES_GTK) | 37 #if defined(TOOLKIT_USES_GTK) |
39 #include "views/widget/native_widget_gtk.h" | 38 #include "views/widget/native_widget_gtk.h" |
40 #endif | 39 #endif |
41 | 40 |
42 using views::ColumnSet; | 41 using views::ColumnSet; |
43 using views::GridLayout; | 42 using views::GridLayout; |
44 | 43 |
45 // Padding between "Title:" and the actual title. | 44 // Padding between "Title:" and the actual title. |
46 static const int kTitlePadding = 4; | 45 static const int kTitlePadding = 4; |
47 | 46 |
48 // Minimum width for the fields - they will push out the size of the bubble if | 47 // Minimum width for the fields - they will push out the size of the bubble if |
49 // necessary. This should be big enough so that the field pushes the right side | 48 // necessary. This should be big enough so that the field pushes the right side |
50 // of the bubble far enough so that the edit button's left edge is to the right | 49 // of the bubble far enough so that the edit button's left edge is to the right |
51 // of the field's left edge. | 50 // of the field's left edge. |
52 static const int kMinimumFieldSize = 180; | 51 static const int kMinimumFieldSize = 180; |
53 | 52 |
54 // Bubble close image. | |
55 static SkBitmap* kCloseImage = NULL; | |
56 | |
57 // Declared in browser_dialogs.h so callers don't have to depend on our header. | 53 // Declared in browser_dialogs.h so callers don't have to depend on our header. |
58 | 54 |
59 namespace browser { | 55 namespace browser { |
60 | 56 |
61 void ShowBookmarkBubbleView(views::Widget* parent, | 57 void ShowBookmarkBubbleView(views::Widget* parent, |
62 const gfx::Rect& bounds, | 58 const gfx::Rect& bounds, |
63 BubbleDelegate* delegate, | 59 BubbleDelegate* delegate, |
64 Profile* profile, | 60 Profile* profile, |
65 const GURL& url, | 61 const GURL& url, |
66 bool newly_bookmarked) { | 62 bool newly_bookmarked) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 url_(url), | 168 url_(url), |
173 newly_bookmarked_(newly_bookmarked), | 169 newly_bookmarked_(newly_bookmarked), |
174 parent_model_( | 170 parent_model_( |
175 profile_->GetBookmarkModel(), | 171 profile_->GetBookmarkModel(), |
176 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), | 172 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), |
177 remove_bookmark_(false), | 173 remove_bookmark_(false), |
178 apply_edits_(true) { | 174 apply_edits_(true) { |
179 } | 175 } |
180 | 176 |
181 void BookmarkBubbleView::Init() { | 177 void BookmarkBubbleView::Init() { |
182 static SkColor kTitleColor; | |
183 static bool initialized = false; | |
184 if (!initialized) { | |
185 kTitleColor = color_utils::GetReadableColor(SkColorSetRGB(6, 45, 117), | |
186 Bubble::kBackgroundColor); | |
187 kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
188 IDR_INFO_BUBBLE_CLOSE); | |
189 | |
190 initialized = true; | |
191 } | |
192 | |
193 remove_link_ = new views::Link(l10n_util::GetStringUTF16( | 178 remove_link_ = new views::Link(l10n_util::GetStringUTF16( |
194 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | 179 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); |
195 remove_link_->set_listener(this); | 180 remove_link_->set_listener(this); |
| 181 remove_link_->SetBackgroundColor(Bubble::kBackgroundColor); |
196 | 182 |
197 edit_button_ = new views::NativeTextButton( | 183 edit_button_ = new views::NativeTextButton( |
198 this, | 184 this, |
199 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS))); | 185 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS))); |
200 | 186 |
201 close_button_ = new views::NativeTextButton( | 187 close_button_ = new views::NativeTextButton( |
202 this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_DONE))); | 188 this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_DONE))); |
203 close_button_->SetIsDefault(true); | 189 close_button_->SetIsDefault(true); |
204 | 190 |
205 views::Label* combobox_label = new views::Label( | 191 views::Label* combobox_label = new views::Label( |
206 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 192 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
| 193 combobox_label->SetBackgroundColor(Bubble::kBackgroundColor); |
207 | 194 |
208 parent_combobox_ = new views::Combobox(&parent_model_); | 195 parent_combobox_ = new views::Combobox(&parent_model_); |
209 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); | 196 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); |
210 parent_combobox_->set_listener(this); | 197 parent_combobox_->set_listener(this); |
211 parent_combobox_->SetAccessibleName(combobox_label->GetText()); | 198 parent_combobox_->SetAccessibleName(combobox_label->GetText()); |
212 | 199 |
213 views::Label* title_label = new views::Label( | 200 views::Label* title_label = new views::Label( |
214 l10n_util::GetStringUTF16( | 201 l10n_util::GetStringUTF16( |
215 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : | 202 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : |
216 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); | 203 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); |
217 title_label->SetFont( | 204 title_label->SetFont( |
218 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); | 205 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); |
219 title_label->SetColor(kTitleColor); | 206 title_label->SetBackgroundColor(Bubble::kBackgroundColor); |
| 207 title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117)); |
220 | 208 |
221 GridLayout* layout = new GridLayout(this); | 209 GridLayout* layout = new GridLayout(this); |
222 SetLayoutManager(layout); | 210 SetLayoutManager(layout); |
223 | 211 |
224 ColumnSet* cs = layout->AddColumnSet(0); | 212 ColumnSet* cs = layout->AddColumnSet(0); |
225 | 213 |
226 // Top (title) row. | 214 // Top (title) row. |
227 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 215 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
228 0, 0); | 216 0, 0); |
229 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 217 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
(...skipping 19 matching lines...) Expand all Loading... |
249 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); | 237 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
250 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 238 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
251 GridLayout::USE_PREF, 0, 0); | 239 GridLayout::USE_PREF, 0, 0); |
252 | 240 |
253 layout->StartRow(0, 0); | 241 layout->StartRow(0, 0); |
254 layout->AddView(title_label); | 242 layout->AddView(title_label); |
255 layout->AddView(remove_link_); | 243 layout->AddView(remove_link_); |
256 | 244 |
257 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 245 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
258 layout->StartRow(0, 2); | 246 layout->StartRow(0, 2); |
259 layout->AddView(new views::Label( | 247 views::Label* label = new views::Label( |
260 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT))); | 248 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
| 249 label->SetBackgroundColor(Bubble::kBackgroundColor); |
| 250 layout->AddView(label); |
261 title_tf_ = new views::Textfield(); | 251 title_tf_ = new views::Textfield(); |
262 title_tf_->SetText(GetTitle()); | 252 title_tf_->SetText(GetTitle()); |
263 layout->AddView(title_tf_); | 253 layout->AddView(title_tf_); |
264 | 254 |
265 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 255 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
266 | 256 |
267 layout->StartRow(0, 2); | 257 layout->StartRow(0, 2); |
268 layout->AddView(combobox_label); | 258 layout->AddView(combobox_label); |
269 layout->AddView(parent_combobox_); | 259 layout->AddView(parent_combobox_); |
270 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 260 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 325 } |
336 | 326 |
337 bool BookmarkBubbleView::CloseOnEscape() { | 327 bool BookmarkBubbleView::CloseOnEscape() { |
338 return delegate_ ? delegate_->CloseOnEscape() : true; | 328 return delegate_ ? delegate_->CloseOnEscape() : true; |
339 } | 329 } |
340 | 330 |
341 bool BookmarkBubbleView::FadeInOnShow() { | 331 bool BookmarkBubbleView::FadeInOnShow() { |
342 return false; | 332 return false; |
343 } | 333 } |
344 | 334 |
345 string16 BookmarkBubbleView::accessible_name() { | 335 string16 BookmarkBubbleView::GetAccessibleName() { |
346 return l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK); | 336 return l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK); |
347 } | 337 } |
348 | 338 |
349 void BookmarkBubbleView::Close() { | 339 void BookmarkBubbleView::Close() { |
350 ApplyEdits(); | 340 ApplyEdits(); |
351 GetWidget()->Close(); | 341 GetWidget()->Close(); |
352 } | 342 } |
353 | 343 |
354 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 344 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
355 if (sender == edit_button_) { | 345 if (sender == edit_button_) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 const BookmarkNode* new_parent = | 410 const BookmarkNode* new_parent = |
421 parent_model_.GetNodeAt(parent_combobox_->selected_item()); | 411 parent_model_.GetNodeAt(parent_combobox_->selected_item()); |
422 if (new_parent != node->parent()) { | 412 if (new_parent != node->parent()) { |
423 UserMetrics::RecordAction( | 413 UserMetrics::RecordAction( |
424 UserMetricsAction("BookmarkBubble_ChangeParent")); | 414 UserMetricsAction("BookmarkBubble_ChangeParent")); |
425 model->Move(node, new_parent, new_parent->child_count()); | 415 model->Move(node, new_parent, new_parent->child_count()); |
426 } | 416 } |
427 } | 417 } |
428 } | 418 } |
429 } | 419 } |
OLD | NEW |