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 <utility> | |
8 | |
9 #include "base/macros.h" | |
10 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
11 #include "base/strings/string16.h" | |
12 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/app/chrome_command_ids.h" | |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" | 13 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" |
19 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" | 14 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" |
20 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
21 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 16 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
22 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 17 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
23 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" | 18 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" |
24 #include "chrome/grit/chromium_strings.h" | 19 #include "chrome/grit/chromium_strings.h" |
25 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
26 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
27 #include "components/bookmarks/browser/bookmark_utils.h" | 22 #include "components/bookmarks/browser/bookmark_utils.h" |
28 #include "components/strings/grit/components_strings.h" | 23 #include "components/strings/grit/components_strings.h" |
29 #include "ui/accessibility/ax_node_data.h" | 24 #include "ui/accessibility/ax_node_data.h" |
30 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
32 #include "ui/views/bubble/bubble_frame_view.h" | |
33 #include "ui/views/controls/button/md_text_button.h" | 27 #include "ui/views/controls/button/md_text_button.h" |
34 #include "ui/views/controls/combobox/combobox.h" | 28 #include "ui/views/controls/combobox/combobox.h" |
35 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
36 #include "ui/views/controls/link.h" | |
37 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
38 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
39 #include "ui/views/layout/grid_layout.h" | 32 #include "ui/views/layout/grid_layout.h" |
40 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
41 | 34 |
42 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
43 #include "chrome/browser/sync/profile_sync_service_factory.h" | 36 #include "chrome/browser/sync/profile_sync_service_factory.h" |
44 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" | 37 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" |
45 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_fo
otnote_view.h" | 38 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_fo
otnote_view.h" |
46 #include "components/browser_sync/profile_sync_service.h" | 39 #include "components/browser_sync/profile_sync_service.h" |
47 #endif | 40 #endif |
48 | 41 |
49 using base::UserMetricsAction; | 42 using base::UserMetricsAction; |
50 using bookmarks::BookmarkModel; | 43 using bookmarks::BookmarkModel; |
51 using bookmarks::BookmarkNode; | 44 using bookmarks::BookmarkNode; |
52 using views::ColumnSet; | 45 using views::ColumnSet; |
53 using views::GridLayout; | 46 using views::GridLayout; |
54 | 47 |
55 namespace { | 48 namespace { |
56 | 49 |
57 // This combobox prevents any lengthy content from stretching the bubble view. | 50 // This combobox prevents any lengthy content from stretching the bubble view. |
58 class UnsizedCombobox : public views::Combobox { | 51 class UnsizedCombobox : public views::Combobox { |
59 public: | 52 public: |
60 explicit UnsizedCombobox(ui::ComboboxModel* model) : views::Combobox(model) {} | 53 explicit UnsizedCombobox(ui::ComboboxModel* model) : views::Combobox(model) {} |
61 ~UnsizedCombobox() override {} | 54 ~UnsizedCombobox() override {} |
62 | 55 |
| 56 // views::Combobox: |
63 gfx::Size CalculatePreferredSize() const override { | 57 gfx::Size CalculatePreferredSize() const override { |
64 return gfx::Size(0, views::Combobox::CalculatePreferredSize().height()); | 58 return gfx::Size(0, views::Combobox::CalculatePreferredSize().height()); |
65 } | 59 } |
66 | 60 |
67 private: | 61 private: |
68 DISALLOW_COPY_AND_ASSIGN(UnsizedCombobox); | 62 DISALLOW_COPY_AND_ASSIGN(UnsizedCombobox); |
69 }; | 63 }; |
70 | 64 |
71 } // namespace | 65 } // namespace |
72 | 66 |
73 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; | 67 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = nullptr; |
74 | 68 |
75 // static | 69 // static |
76 views::Widget* BookmarkBubbleView::ShowBubble( | 70 views::Widget* BookmarkBubbleView::ShowBubble( |
77 views::View* anchor_view, | 71 views::View* anchor_view, |
78 const gfx::Rect& anchor_rect, | 72 const gfx::Rect& anchor_rect, |
79 gfx::NativeView parent_window, | 73 gfx::NativeView parent_window, |
80 bookmarks::BookmarkBubbleObserver* observer, | 74 bookmarks::BookmarkBubbleObserver* observer, |
81 std::unique_ptr<BubbleSyncPromoDelegate> delegate, | 75 std::unique_ptr<BubbleSyncPromoDelegate> delegate, |
82 Profile* profile, | 76 Profile* profile, |
83 const GURL& url, | 77 const GURL& url, |
84 bool already_bookmarked) { | 78 bool already_bookmarked) { |
85 if (bookmark_bubble_) | 79 if (bookmark_bubble_) |
86 return nullptr; | 80 return nullptr; |
87 | 81 |
88 bookmark_bubble_ = | 82 bookmark_bubble_ = |
89 new BookmarkBubbleView(anchor_view, observer, std::move(delegate), | 83 new BookmarkBubbleView(anchor_view, observer, std::move(delegate), |
90 profile, url, !already_bookmarked); | 84 profile, url, !already_bookmarked); |
91 // Bookmark bubble should always anchor TOP_RIGHT, but the | 85 // Bookmark bubble should always anchor TOP_RIGHT, but the |
92 // LocationBarBubbleDelegateView does not know that and may use different | 86 // LocationBarBubbleDelegateView does not know that and may use different |
93 // arrow anchoring. | 87 // arrow anchoring. |
94 bookmark_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); | 88 bookmark_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); |
95 if (!anchor_view) { | 89 if (!anchor_view) { |
96 bookmark_bubble_->SetAnchorRect(anchor_rect); | 90 bookmark_bubble_->SetAnchorRect(anchor_rect); |
97 bookmark_bubble_->set_parent_window(parent_window); | 91 bookmark_bubble_->set_parent_window(parent_window); |
98 } | 92 } |
99 views::Widget* bubble_widget = | 93 views::Widget* bubble_widget = |
100 views::BubbleDialogDelegateView::CreateBubble(bookmark_bubble_); | 94 views::BubbleDialogDelegateView::CreateBubble(bookmark_bubble_); |
101 bubble_widget->Show(); | 95 bubble_widget->Show(); |
102 // Select the entire title textfield contents when the bubble is first shown. | 96 // Select the entire title textfield contents when the bubble is first shown. |
103 bookmark_bubble_->title_tf_->SelectAll(true); | 97 bookmark_bubble_->name_field_->SelectAll(true); |
104 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 98 bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
105 | 99 |
106 if (bookmark_bubble_->observer_) { | 100 if (bookmark_bubble_->observer_) { |
107 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile); | 101 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile); |
108 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); | 102 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); |
109 bookmark_bubble_->observer_->OnBookmarkBubbleShown(node); | 103 bookmark_bubble_->observer_->OnBookmarkBubbleShown(node); |
110 } | 104 } |
111 return bubble_widget; | 105 return bubble_widget; |
112 } | 106 } |
113 | 107 |
| 108 // static |
114 void BookmarkBubbleView::Hide() { | 109 void BookmarkBubbleView::Hide() { |
115 if (bookmark_bubble_) | 110 if (bookmark_bubble_) |
116 bookmark_bubble_->GetWidget()->Close(); | 111 bookmark_bubble_->GetWidget()->Close(); |
117 } | 112 } |
118 | 113 |
119 BookmarkBubbleView::~BookmarkBubbleView() { | 114 BookmarkBubbleView::~BookmarkBubbleView() { |
120 if (apply_edits_) { | 115 if (apply_edits_) { |
121 ApplyEdits(); | 116 ApplyEdits(); |
122 } else if (remove_bookmark_) { | 117 } else if (remove_bookmark_) { |
123 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_); | 118 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_); |
124 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); | 119 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); |
125 if (node) | 120 if (node) |
126 model->Remove(node); | 121 model->Remove(node); |
127 } | 122 } |
128 // |parent_combobox_| needs to be destroyed before |parent_model_| as it | 123 // |parent_combobox_| needs to be destroyed before |parent_model_| as it |
129 // uses |parent_model_| in its destructor. | 124 // uses |parent_model_| in its destructor. |
130 delete parent_combobox_; | 125 delete parent_combobox_; |
131 } | 126 } |
132 | 127 |
| 128 // ui::DialogModel ------------------------------------------------------------- |
| 129 |
| 130 int BookmarkBubbleView::GetDialogButtons() const { |
| 131 // TODO(tapted): DialogClientView should manage the buttons. |
| 132 return ui::DIALOG_BUTTON_NONE; |
| 133 } |
| 134 |
133 // views::WidgetDelegate ------------------------------------------------------- | 135 // views::WidgetDelegate ------------------------------------------------------- |
134 | 136 |
135 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 137 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
136 return title_tf_; | 138 return name_field_; |
137 } | 139 } |
138 | 140 |
139 base::string16 BookmarkBubbleView::GetWindowTitle() const { | 141 base::string16 BookmarkBubbleView::GetWindowTitle() const { |
140 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
141 if (is_showing_ios_promotion_) { | 143 if (is_showing_ios_promotion_) { |
142 return desktop_ios_promotion::GetPromoTitle( | 144 return desktop_ios_promotion::GetPromoTitle( |
143 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | 145 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); |
144 } | 146 } |
145 #endif | 147 #endif |
146 return l10n_util::GetStringUTF16(newly_bookmarked_ | 148 return l10n_util::GetStringUTF16(newly_bookmarked_ |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // views::View ----------------------------------------------------------------- | 201 // views::View ----------------------------------------------------------------- |
200 | 202 |
201 const char* BookmarkBubbleView::GetClassName() const { | 203 const char* BookmarkBubbleView::GetClassName() const { |
202 return "BookmarkBubbleView"; | 204 return "BookmarkBubbleView"; |
203 } | 205 } |
204 | 206 |
205 bool BookmarkBubbleView::AcceleratorPressed( | 207 bool BookmarkBubbleView::AcceleratorPressed( |
206 const ui::Accelerator& accelerator) { | 208 const ui::Accelerator& accelerator) { |
207 ui::KeyboardCode key_code = accelerator.key_code(); | 209 ui::KeyboardCode key_code = accelerator.key_code(); |
208 if (key_code == ui::VKEY_RETURN) { | 210 if (key_code == ui::VKEY_RETURN) { |
209 HandleButtonPressed(close_button_); | 211 HandleButtonPressed(save_button_); |
210 return true; | 212 return true; |
211 } | 213 } |
212 if (key_code == ui::VKEY_E && accelerator.IsAltDown()) { | 214 if (key_code == ui::VKEY_E && accelerator.IsAltDown()) { |
213 HandleButtonPressed(edit_button_); | 215 HandleButtonPressed(edit_button_); |
214 return true; | 216 return true; |
215 } | 217 } |
216 if (key_code == ui::VKEY_R && accelerator.IsAltDown()) { | 218 if (key_code == ui::VKEY_R && accelerator.IsAltDown()) { |
217 HandleButtonPressed(remove_button_); | 219 HandleButtonPressed(remove_button_); |
218 return true; | 220 return true; |
219 } | 221 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 257 |
256 // views::BubbleDialogDelegateView --------------------------------------------- | 258 // views::BubbleDialogDelegateView --------------------------------------------- |
257 | 259 |
258 void BookmarkBubbleView::Init() { | 260 void BookmarkBubbleView::Init() { |
259 remove_button_ = views::MdTextButton::CreateSecondaryUiButton( | 261 remove_button_ = views::MdTextButton::CreateSecondaryUiButton( |
260 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | 262 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); |
261 | 263 |
262 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( | 264 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( |
263 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 265 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); |
264 | 266 |
265 close_button_ = views::MdTextButton::CreateSecondaryUiButton( | 267 save_button_ = views::MdTextButton::CreateSecondaryUiButton( |
266 this, l10n_util::GetStringUTF16(IDS_DONE)); | 268 this, l10n_util::GetStringUTF16(IDS_DONE)); |
267 close_button_->SetIsDefault(true); | 269 save_button_->SetIsDefault(true); |
268 | 270 |
269 views::Label* combobox_label = new views::Label( | 271 views::Label* combobox_label = new views::Label( |
270 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 272 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
271 | 273 |
272 parent_combobox_ = new UnsizedCombobox(&parent_model_); | 274 parent_combobox_ = new UnsizedCombobox(&parent_model_); |
273 parent_combobox_->set_listener(this); | 275 parent_combobox_->set_listener(this); |
274 parent_combobox_->SetAccessibleName( | 276 parent_combobox_->SetAccessibleName( |
275 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); | 277 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); |
276 | 278 |
277 SetLayoutManager(new views::FillLayout); | 279 SetLayoutManager(new views::FillLayout); |
278 bookmark_details_view_ = base::MakeUnique<View>(); | 280 bookmark_contents_view_ = new views::View(); |
279 GridLayout* layout = new GridLayout(bookmark_details_view_.get()); | 281 GridLayout* layout = new GridLayout(bookmark_contents_view_); |
280 bookmark_details_view_->SetLayoutManager(layout); | 282 bookmark_contents_view_->SetLayoutManager(layout); |
281 | 283 |
282 // This column set is used for the labels and textfields as well as the | 284 // This column set is used for the labels and textfields as well as the |
283 // buttons at the bottom. | 285 // buttons at the bottom. |
284 const int cs_id = 0; | 286 const int cs_id = 0; |
285 ColumnSet* cs = layout->AddColumnSet(cs_id); | 287 ColumnSet* cs = layout->AddColumnSet(cs_id); |
286 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | 288 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
287 | 289 |
288 cs->AddColumn(provider->GetControlLabelGridAlignment(), GridLayout::CENTER, 0, | 290 cs->AddColumn(provider->GetControlLabelGridAlignment(), GridLayout::CENTER, 0, |
289 GridLayout::USE_PREF, 0, 0); | 291 GridLayout::USE_PREF, 0, 0); |
290 cs->AddPaddingColumn( | 292 cs->AddPaddingColumn( |
291 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); | 293 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); |
292 | 294 |
293 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | 295 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
294 GridLayout::USE_PREF, 0, 0); | 296 0, 0); |
295 cs->AddPaddingColumn(1, provider->GetDistanceMetric( | 297 cs->AddPaddingColumn(1, provider->GetDistanceMetric( |
296 DISTANCE_UNRELATED_CONTROL_HORIZONTAL_LARGE)); | 298 DISTANCE_UNRELATED_CONTROL_HORIZONTAL_LARGE)); |
297 | 299 |
298 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 300 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
299 GridLayout::USE_PREF, 0, 0); | 301 GridLayout::USE_PREF, 0, 0); |
300 cs->AddPaddingColumn(0, provider->GetDistanceMetric( | 302 cs->AddPaddingColumn(0, provider->GetDistanceMetric( |
301 views::DISTANCE_RELATED_BUTTON_HORIZONTAL)); | 303 views::DISTANCE_RELATED_BUTTON_HORIZONTAL)); |
302 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 304 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
303 GridLayout::USE_PREF, 0, 0); | 305 GridLayout::USE_PREF, 0, 0); |
304 | 306 |
305 layout->StartRow(0, cs_id); | 307 layout->StartRow(0, cs_id); |
306 views::Label* label = new views::Label( | 308 views::Label* label = new views::Label( |
307 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 309 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
308 layout->AddView(label); | 310 layout->AddView(label); |
309 title_tf_ = new views::Textfield(); | 311 name_field_ = new views::Textfield(); |
310 title_tf_->SetText(GetTitle()); | 312 name_field_->SetText(GetBookmarkName()); |
311 title_tf_->SetAccessibleName( | 313 name_field_->SetAccessibleName( |
312 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_TITLE_TEXT)); | 314 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_TITLE_TEXT)); |
313 | 315 |
314 layout->AddView(title_tf_, 5, 1); | 316 layout->AddView(name_field_, 5, 1); |
315 | 317 |
316 layout->AddPaddingRow( | 318 layout->AddPaddingRow( |
317 0, provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).top()); | 319 0, provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).top()); |
318 | 320 |
319 layout->StartRow(0, cs_id); | 321 layout->StartRow(0, cs_id); |
320 layout->AddView(combobox_label); | 322 layout->AddView(combobox_label); |
321 layout->AddView(parent_combobox_, 5, 1); | 323 layout->AddView(parent_combobox_, 5, 1); |
322 | 324 |
323 layout->AddPaddingRow( | 325 layout->AddPaddingRow( |
324 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); | 326 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); |
325 | 327 |
326 layout->StartRow(0, cs_id); | 328 layout->StartRow(0, cs_id); |
327 layout->SkipColumns(2); | 329 layout->SkipColumns(2); |
328 layout->AddView(remove_button_); | 330 layout->AddView(remove_button_); |
329 layout->AddView(edit_button_); | 331 layout->AddView(edit_button_); |
330 layout->AddView(close_button_); | 332 layout->AddView(save_button_); |
331 | 333 |
332 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 334 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
333 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); | 335 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); |
334 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); | 336 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); |
335 | 337 |
336 AddChildView(bookmark_details_view_.get()); | 338 AddChildView(bookmark_contents_view_); |
337 } | 339 } |
338 | 340 |
339 // Private methods ------------------------------------------------------------- | 341 // Private methods ------------------------------------------------------------- |
340 | 342 |
341 BookmarkBubbleView::BookmarkBubbleView( | 343 BookmarkBubbleView::BookmarkBubbleView( |
342 views::View* anchor_view, | 344 views::View* anchor_view, |
343 bookmarks::BookmarkBubbleObserver* observer, | 345 bookmarks::BookmarkBubbleObserver* observer, |
344 std::unique_ptr<BubbleSyncPromoDelegate> delegate, | 346 std::unique_ptr<BubbleSyncPromoDelegate> delegate, |
345 Profile* profile, | 347 Profile* profile, |
346 const GURL& url, | 348 const GURL& url, |
347 bool newly_bookmarked) | 349 bool newly_bookmarked) |
348 : LocationBarBubbleDelegateView(anchor_view, nullptr), | 350 : LocationBarBubbleDelegateView(anchor_view, nullptr), |
349 observer_(observer), | 351 observer_(observer), |
350 delegate_(std::move(delegate)), | 352 delegate_(std::move(delegate)), |
351 profile_(profile), | 353 profile_(profile), |
352 url_(url), | 354 url_(url), |
353 newly_bookmarked_(newly_bookmarked), | 355 newly_bookmarked_(newly_bookmarked), |
354 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), | 356 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), |
355 BookmarkModelFactory::GetForBrowserContext(profile_) | 357 BookmarkModelFactory::GetForBrowserContext(profile_) |
356 ->GetMostRecentlyAddedUserNodeForURL(url)), | 358 ->GetMostRecentlyAddedUserNodeForURL(url)), |
357 remove_button_(nullptr), | 359 remove_button_(nullptr), |
358 edit_button_(nullptr), | 360 edit_button_(nullptr), |
359 close_button_(nullptr), | 361 save_button_(nullptr), |
360 title_tf_(nullptr), | 362 name_field_(nullptr), |
361 parent_combobox_(nullptr), | 363 parent_combobox_(nullptr), |
362 ios_promo_view_(nullptr), | 364 ios_promo_view_(nullptr), |
363 footnote_view_(nullptr), | 365 footnote_view_(nullptr), |
364 remove_bookmark_(false), | 366 remove_bookmark_(false), |
365 apply_edits_(true), | 367 apply_edits_(true), |
366 is_showing_ios_promotion_(false) { | 368 is_showing_ios_promotion_(false) { |
367 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); | 369 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); |
368 } | 370 } |
369 | 371 |
370 base::string16 BookmarkBubbleView::GetTitle() { | 372 base::string16 BookmarkBubbleView::GetBookmarkName() { |
371 BookmarkModel* bookmark_model = | 373 BookmarkModel* bookmark_model = |
372 BookmarkModelFactory::GetForBrowserContext(profile_); | 374 BookmarkModelFactory::GetForBrowserContext(profile_); |
373 const BookmarkNode* node = | 375 const BookmarkNode* node = |
374 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); | 376 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); |
375 if (node) | 377 if (node) |
376 return node->GetTitle(); | 378 return node->GetTitle(); |
377 else | 379 else |
378 NOTREACHED(); | 380 NOTREACHED(); |
379 return base::string16(); | 381 return base::string16(); |
380 } | 382 } |
381 | 383 |
382 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 384 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
383 if (sender == remove_button_) { | 385 if (sender == remove_button_) { |
384 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | 386 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); |
385 // Set this so we remove the bookmark after the window closes. | 387 // Set this so we remove the bookmark after the window closes. |
386 remove_bookmark_ = true; | 388 remove_bookmark_ = true; |
387 apply_edits_ = false; | 389 apply_edits_ = false; |
388 GetWidget()->Close(); | 390 GetWidget()->Close(); |
389 } else if (sender == edit_button_) { | 391 } else if (sender == edit_button_) { |
390 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 392 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
391 ShowEditor(); | 393 ShowEditor(); |
392 } else { | 394 } else { |
393 DCHECK_EQ(close_button_, sender); | 395 DCHECK_EQ(save_button_, sender); |
394 #if defined(OS_WIN) | 396 #if defined(OS_WIN) |
395 if (IsIOSPromotionEligible( | 397 if (IsIOSPromotionEligible( |
396 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { | 398 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { |
397 ShowIOSPromotion( | 399 ShowIOSPromotion( |
398 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | 400 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); |
399 } else { | 401 } else { |
400 GetWidget()->Close(); | 402 GetWidget()->Close(); |
401 } | 403 } |
402 #else | 404 #else |
403 GetWidget()->Close(); | 405 GetWidget()->Close(); |
(...skipping 20 matching lines...) Expand all Loading... |
424 BookmarkEditor::SHOW_TREE); | 426 BookmarkEditor::SHOW_TREE); |
425 } | 427 } |
426 | 428 |
427 void BookmarkBubbleView::ApplyEdits() { | 429 void BookmarkBubbleView::ApplyEdits() { |
428 // Set this to make sure we don't attempt to apply edits again. | 430 // Set this to make sure we don't attempt to apply edits again. |
429 apply_edits_ = false; | 431 apply_edits_ = false; |
430 | 432 |
431 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_); | 433 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_); |
432 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); | 434 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); |
433 if (node) { | 435 if (node) { |
434 const base::string16 new_title = title_tf_->text(); | 436 const base::string16 new_title = name_field_->text(); |
435 if (new_title != node->GetTitle()) { | 437 if (new_title != node->GetTitle()) { |
436 model->SetTitle(node, new_title); | 438 model->SetTitle(node, new_title); |
437 base::RecordAction( | 439 base::RecordAction( |
438 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 440 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
439 } | 441 } |
440 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 442 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
441 } | 443 } |
442 } | 444 } |
443 | 445 |
444 #if defined(OS_WIN) | 446 #if defined(OS_WIN) |
445 | 447 |
446 bool BookmarkBubbleView::IsIOSPromotionEligible( | 448 bool BookmarkBubbleView::IsIOSPromotionEligible( |
447 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 449 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
448 PrefService* prefs = profile_->GetPrefs(); | 450 PrefService* prefs = profile_->GetPrefs(); |
449 const browser_sync::ProfileSyncService* sync_service = | 451 const browser_sync::ProfileSyncService* sync_service = |
450 ProfileSyncServiceFactory::GetForProfile(profile_); | 452 ProfileSyncServiceFactory::GetForProfile(profile_); |
451 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, | 453 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, |
452 entry_point); | 454 entry_point); |
453 } | 455 } |
454 | 456 |
455 void BookmarkBubbleView::ShowIOSPromotion( | 457 void BookmarkBubbleView::ShowIOSPromotion( |
456 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 458 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
457 DCHECK(!is_showing_ios_promotion_); | 459 DCHECK(!is_showing_ios_promotion_); |
458 RemoveChildView(bookmark_details_view_.get()); | 460 // Hide the contents, but don't delete. Its child views are accessed in the |
| 461 // destructor if there are edits to apply. |
| 462 bookmark_contents_view_->SetVisible(false); |
459 delete footnote_view_; | 463 delete footnote_view_; |
460 footnote_view_ = nullptr; | 464 footnote_view_ = nullptr; |
461 is_showing_ios_promotion_ = true; | 465 is_showing_ios_promotion_ = true; |
462 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); | 466 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); |
463 AddChildView(ios_promo_view_); | 467 AddChildView(ios_promo_view_); |
464 GetWidget()->UpdateWindowIcon(); | 468 GetWidget()->UpdateWindowIcon(); |
465 GetWidget()->UpdateWindowTitle(); | 469 GetWidget()->UpdateWindowTitle(); |
466 // Resize the bubble so it has the same width as the parent bubble. | 470 // Resize the bubble so it has the same width as the parent bubble. |
467 ios_promo_view_->UpdateBubbleHeight(); | 471 ios_promo_view_->UpdateBubbleHeight(); |
468 } | 472 } |
469 #endif | 473 #endif |
OLD | NEW |