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 "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "ui/accessibility/ax_node_data.h" | 24 #include "ui/accessibility/ax_node_data.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
27 #include "ui/views/controls/button/md_text_button.h" | 27 #include "ui/views/controls/button/md_text_button.h" |
28 #include "ui/views/controls/combobox/combobox.h" | 28 #include "ui/views/controls/combobox/combobox.h" |
29 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
30 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
31 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
32 #include "ui/views/layout/grid_layout.h" | 32 #include "ui/views/layout/grid_layout.h" |
33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
34 #include "ui/views/window/dialog_client_view.h" | |
34 | 35 |
35 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
36 #include "chrome/browser/sync/profile_sync_service_factory.h" | 37 #include "chrome/browser/sync/profile_sync_service_factory.h" |
37 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h" | 38 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h" |
38 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_fo otnote_view.h" | 39 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_fo otnote_view.h" |
39 #include "components/browser_sync/profile_sync_service.h" | 40 #include "components/browser_sync/profile_sync_service.h" |
40 #endif | 41 #endif |
41 | 42 |
42 using base::UserMetricsAction; | 43 using base::UserMetricsAction; |
43 using bookmarks::BookmarkModel; | 44 using bookmarks::BookmarkModel; |
44 using bookmarks::BookmarkNode; | 45 using bookmarks::BookmarkNode; |
45 using views::ColumnSet; | |
46 using views::GridLayout; | |
47 | 46 |
48 namespace { | 47 namespace { |
49 | 48 |
50 // This combobox prevents any lengthy content from stretching the bubble view. | 49 // This combobox prevents any lengthy content from stretching the bubble view. |
51 class UnsizedCombobox : public views::Combobox { | 50 class UnsizedCombobox : public views::Combobox { |
52 public: | 51 public: |
53 explicit UnsizedCombobox(ui::ComboboxModel* model) : views::Combobox(model) {} | 52 explicit UnsizedCombobox(ui::ComboboxModel* model) : views::Combobox(model) {} |
54 ~UnsizedCombobox() override {} | 53 ~UnsizedCombobox() override {} |
55 | 54 |
56 // views::Combobox: | 55 // views::Combobox: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 model->Remove(node); | 120 model->Remove(node); |
122 } | 121 } |
123 // |parent_combobox_| needs to be destroyed before |parent_model_| as it | 122 // |parent_combobox_| needs to be destroyed before |parent_model_| as it |
124 // uses |parent_model_| in its destructor. | 123 // uses |parent_model_| in its destructor. |
125 delete parent_combobox_; | 124 delete parent_combobox_; |
126 } | 125 } |
127 | 126 |
128 // ui::DialogModel ------------------------------------------------------------- | 127 // ui::DialogModel ------------------------------------------------------------- |
129 | 128 |
130 int BookmarkBubbleView::GetDialogButtons() const { | 129 int BookmarkBubbleView::GetDialogButtons() const { |
131 // TODO(tapted): DialogClientView should manage the buttons. | 130 // TODO(tapted): DialogClientView should manage the ios promo buttons too. |
132 return ui::DIALOG_BUTTON_NONE; | 131 return is_showing_ios_promotion_ |
132 ? ui::DIALOG_BUTTON_NONE | |
133 : (ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL); | |
134 } | |
135 | |
136 base::string16 BookmarkBubbleView::GetDialogButtonLabel( | |
137 ui::DialogButton button) const { | |
138 switch (button) { | |
139 case ui::DIALOG_BUTTON_OK: | |
140 return l10n_util::GetStringUTF16(IDS_DONE); | |
141 case ui::DIALOG_BUTTON_CANCEL: | |
142 return l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK); | |
143 case ui::DIALOG_BUTTON_NONE: | |
144 NOTREACHED(); | |
145 break; | |
146 } | |
147 return base::string16(); | |
Peter Kasting
2017/05/31 02:43:31
Nit: Simpler:
return l10n_util::GetStringUTF16(
tapted
2017/05/31 04:27:48
Done.
| |
133 } | 148 } |
134 | 149 |
135 // views::WidgetDelegate ------------------------------------------------------- | 150 // views::WidgetDelegate ------------------------------------------------------- |
136 | 151 |
137 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 152 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
138 return name_field_; | 153 return name_field_; |
139 } | 154 } |
140 | 155 |
141 base::string16 BookmarkBubbleView::GetWindowTitle() const { | 156 base::string16 BookmarkBubbleView::GetWindowTitle() const { |
142 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
(...skipping 28 matching lines...) Expand all Loading... | |
171 DCHECK_EQ(bookmark_bubble_, this); | 186 DCHECK_EQ(bookmark_bubble_, this); |
172 bookmark_bubble_ = NULL; | 187 bookmark_bubble_ = NULL; |
173 is_showing_ios_promotion_ = false; | 188 is_showing_ios_promotion_ = false; |
174 | 189 |
175 if (observer_) | 190 if (observer_) |
176 observer_->OnBookmarkBubbleHidden(); | 191 observer_->OnBookmarkBubbleHidden(); |
177 } | 192 } |
178 | 193 |
179 // views::DialogDelegate ------------------------------------------------------- | 194 // views::DialogDelegate ------------------------------------------------------- |
180 | 195 |
196 views::View* BookmarkBubbleView::CreateExtraView() { | |
197 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( | |
198 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | |
199 edit_button_->AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); | |
200 return edit_button_; | |
201 } | |
202 | |
203 bool BookmarkBubbleView::GetExtraViewPadding(int* padding) { | |
204 *padding = ChromeLayoutProvider::Get()->GetDistanceMetric( | |
205 DISTANCE_UNRELATED_CONTROL_HORIZONTAL_LARGE); | |
206 return true; | |
207 } | |
208 | |
181 views::View* BookmarkBubbleView::CreateFootnoteView() { | 209 views::View* BookmarkBubbleView::CreateFootnoteView() { |
182 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
183 if (!is_showing_ios_promotion_ && | 211 if (!is_showing_ios_promotion_ && |
184 IsIOSPromotionEligible( | 212 IsIOSPromotionEligible( |
185 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) { | 213 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) { |
186 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this); | 214 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this); |
187 return footnote_view_; | 215 return footnote_view_; |
188 } | 216 } |
189 #endif | 217 #endif |
190 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) | 218 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) |
191 return nullptr; | 219 return nullptr; |
192 | 220 |
193 base::RecordAction(UserMetricsAction("Signin_Impression_FromBookmarkBubble")); | 221 base::RecordAction(UserMetricsAction("Signin_Impression_FromBookmarkBubble")); |
194 | 222 |
195 footnote_view_ = | 223 footnote_view_ = |
196 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, | 224 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, |
197 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); | 225 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); |
198 return footnote_view_; | 226 return footnote_view_; |
199 } | 227 } |
200 | 228 |
229 bool BookmarkBubbleView::Cancel() { | |
230 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
231 // Set this so we remove the bookmark after the window closes. | |
232 remove_bookmark_ = true; | |
233 apply_edits_ = false; | |
234 return true; | |
235 } | |
236 | |
237 bool BookmarkBubbleView::Accept() { | |
238 #if defined(OS_WIN) | |
239 if (IsIOSPromotionEligible( | |
240 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { | |
Peter Kasting
2017/05/31 02:43:31
Nit: Maybe "using desktop_ios_promotion::Promotion
tapted
2017/05/31 04:27:49
Done.
| |
241 ShowIOSPromotion( | |
242 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
243 return false; | |
244 } | |
245 #endif | |
246 return true; | |
247 } | |
248 | |
249 bool BookmarkBubbleView::Close() { | |
250 // Allow closing when activation lost. Default would call Accept(). | |
251 return true; | |
252 } | |
253 | |
254 void BookmarkBubbleView::UpdateButton(views::LabelButton* button, | |
255 ui::DialogButton type) { | |
256 LocationBarBubbleDelegateView::UpdateButton(button, type); | |
257 if (type == ui::DIALOG_BUTTON_CANCEL) | |
258 button->AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); | |
259 } | |
260 | |
201 // views::View ----------------------------------------------------------------- | 261 // views::View ----------------------------------------------------------------- |
202 | 262 |
203 const char* BookmarkBubbleView::GetClassName() const { | 263 const char* BookmarkBubbleView::GetClassName() const { |
204 return "BookmarkBubbleView"; | 264 return "BookmarkBubbleView"; |
205 } | 265 } |
206 | 266 |
207 bool BookmarkBubbleView::AcceleratorPressed( | |
208 const ui::Accelerator& accelerator) { | |
209 ui::KeyboardCode key_code = accelerator.key_code(); | |
210 if (key_code == ui::VKEY_RETURN) { | |
211 HandleButtonPressed(save_button_); | |
212 return true; | |
213 } | |
214 if (key_code == ui::VKEY_E && accelerator.IsAltDown()) { | |
215 HandleButtonPressed(edit_button_); | |
216 return true; | |
217 } | |
218 if (key_code == ui::VKEY_R && accelerator.IsAltDown()) { | |
219 HandleButtonPressed(remove_button_); | |
220 return true; | |
221 } | |
222 | |
223 return LocationBarBubbleDelegateView::AcceleratorPressed(accelerator); | |
224 } | |
225 | |
226 void BookmarkBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 267 void BookmarkBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
227 LocationBarBubbleDelegateView::GetAccessibleNodeData(node_data); | 268 LocationBarBubbleDelegateView::GetAccessibleNodeData(node_data); |
228 node_data->SetName(l10n_util::GetStringUTF8( | 269 node_data->SetName(l10n_util::GetStringUTF8( |
229 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED | 270 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED |
230 : IDS_BOOKMARK_AX_BUBBLE_PAGE_BOOKMARK)); | 271 : IDS_BOOKMARK_AX_BUBBLE_PAGE_BOOKMARK)); |
231 } | 272 } |
232 | 273 |
233 // views::ButtonListener ------------------------------------------------------- | 274 // views::ButtonListener ------------------------------------------------------- |
234 | 275 |
235 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 276 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
236 const ui::Event& event) { | 277 const ui::Event& event) { |
237 HandleButtonPressed(sender); | 278 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
279 ShowEditor(); | |
238 } | 280 } |
239 | 281 |
240 // views::ComboboxListener ----------------------------------------------------- | 282 // views::ComboboxListener ----------------------------------------------------- |
241 | 283 |
242 void BookmarkBubbleView::OnPerformAction(views::Combobox* combobox) { | 284 void BookmarkBubbleView::OnPerformAction(views::Combobox* combobox) { |
243 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 285 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
244 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 286 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
245 ShowEditor(); | 287 ShowEditor(); |
246 } | 288 } |
247 } | 289 } |
248 | 290 |
249 // DesktopIOSPromotionFootnoteDelegate ----------------------------------------- | 291 // DesktopIOSPromotionFootnoteDelegate ----------------------------------------- |
250 | 292 |
251 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() { | 293 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() { |
252 #if defined(OS_WIN) | 294 #if defined(OS_WIN) |
253 ShowIOSPromotion( | 295 ShowIOSPromotion( |
254 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE); | 296 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE); |
255 #endif | 297 #endif |
256 } | 298 } |
257 | 299 |
258 // views::BubbleDialogDelegateView --------------------------------------------- | 300 // views::BubbleDialogDelegateView --------------------------------------------- |
259 | 301 |
260 void BookmarkBubbleView::Init() { | 302 void BookmarkBubbleView::Init() { |
261 remove_button_ = views::MdTextButton::CreateSecondaryUiButton( | 303 using views::GridLayout; |
262 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | |
263 | 304 |
264 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( | 305 SetLayoutManager(new views::FillLayout()); |
265 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 306 bookmark_contents_view_ = new views::View(); |
307 GridLayout* layout = new GridLayout(bookmark_contents_view_); | |
308 bookmark_contents_view_->SetLayoutManager(layout); | |
266 | 309 |
267 save_button_ = views::MdTextButton::CreateSecondaryUiButton( | 310 // This column set is used for the labels and textfields. |
268 this, l10n_util::GetStringUTF16(IDS_DONE)); | 311 constexpr int kColumnId = 0; |
269 save_button_->SetIsDefault(true); | 312 constexpr float kFixed = 0.f; |
313 constexpr float kStretchy = 1.f; | |
314 views::ColumnSet* cs = layout->AddColumnSet(kColumnId); | |
315 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | |
270 | 316 |
317 cs->AddColumn(provider->GetControlLabelGridAlignment(), GridLayout::CENTER, | |
318 kFixed, GridLayout::USE_PREF, 0, 0); | |
319 cs->AddPaddingColumn(kFixed, provider->GetDistanceMetric( | |
320 DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); | |
321 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, kStretchy, | |
322 GridLayout::USE_PREF, 0, 0); | |
323 | |
324 layout->StartRow(kFixed, kColumnId); | |
Peter Kasting
2017/05/31 02:43:31
This block is basically a placeholder until we swi
tapted
2017/05/31 04:27:48
Nah - the title machinery is being used correctly
| |
325 views::Label* label = new views::Label( | |
326 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | |
tapted
2017/05/31 04:27:48
I think this is the bit that makes it confusing ID
| |
327 layout->AddView(label); | |
328 | |
Peter Kasting
2017/05/31 02:43:31
Don't we need to start a new row here or something
tapted
2017/05/31 04:27:48
The top and side padding is handled by |margins_|,
| |
329 name_field_ = new views::Textfield(); | |
330 name_field_->SetText(GetBookmarkName()); | |
331 name_field_->SetAccessibleName( | |
332 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_TITLE_TEXT)); | |
333 layout->AddView(name_field_); | |
334 | |
335 layout->StartRowWithPadding( | |
336 kFixed, kColumnId, kFixed, | |
337 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); | |
271 views::Label* combobox_label = new views::Label( | 338 views::Label* combobox_label = new views::Label( |
272 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 339 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
340 layout->AddView(combobox_label); | |
273 | 341 |
274 parent_combobox_ = new UnsizedCombobox(&parent_model_); | 342 parent_combobox_ = new UnsizedCombobox(&parent_model_); |
275 parent_combobox_->set_listener(this); | 343 parent_combobox_->set_listener(this); |
276 parent_combobox_->SetAccessibleName( | 344 parent_combobox_->SetAccessibleName( |
277 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); | 345 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); |
278 | 346 layout->AddView(parent_combobox_); |
279 SetLayoutManager(new views::FillLayout); | |
280 bookmark_contents_view_ = new views::View(); | |
281 GridLayout* layout = new GridLayout(bookmark_contents_view_); | |
282 bookmark_contents_view_->SetLayoutManager(layout); | |
283 | |
284 // This column set is used for the labels and textfields as well as the | |
285 // buttons at the bottom. | |
286 const int cs_id = 0; | |
287 ColumnSet* cs = layout->AddColumnSet(cs_id); | |
288 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | |
289 | |
290 cs->AddColumn(provider->GetControlLabelGridAlignment(), GridLayout::CENTER, 0, | |
291 GridLayout::USE_PREF, 0, 0); | |
292 cs->AddPaddingColumn( | |
293 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); | |
294 | |
295 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, GridLayout::USE_PREF, | |
296 0, 0); | |
297 cs->AddPaddingColumn(1, provider->GetDistanceMetric( | |
298 DISTANCE_UNRELATED_CONTROL_HORIZONTAL_LARGE)); | |
299 | |
300 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | |
301 GridLayout::USE_PREF, 0, 0); | |
302 cs->AddPaddingColumn(0, provider->GetDistanceMetric( | |
303 views::DISTANCE_RELATED_BUTTON_HORIZONTAL)); | |
304 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | |
305 GridLayout::USE_PREF, 0, 0); | |
306 | |
307 layout->StartRow(0, cs_id); | |
308 views::Label* label = new views::Label( | |
309 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | |
310 layout->AddView(label); | |
311 name_field_ = new views::Textfield(); | |
312 name_field_->SetText(GetBookmarkName()); | |
313 name_field_->SetAccessibleName( | |
314 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_TITLE_TEXT)); | |
315 | |
316 layout->AddView(name_field_, 5, 1); | |
317 | 347 |
318 layout->AddPaddingRow( | 348 layout->AddPaddingRow( |
319 0, provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).top()); | 349 kFixed, |
320 | 350 provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).bottom()); |
Peter Kasting
2017/05/31 02:43:31
Can we just set the dialog contents insets as inse
tapted
2017/05/31 04:27:48
Yeah - this still confounds me :/
Here, we only n
| |
321 layout->StartRow(0, cs_id); | |
322 layout->AddView(combobox_label); | |
323 layout->AddView(parent_combobox_, 5, 1); | |
324 | |
325 layout->AddPaddingRow( | |
326 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); | |
327 | |
328 layout->StartRow(0, cs_id); | |
329 layout->SkipColumns(2); | |
330 layout->AddView(remove_button_); | |
331 layout->AddView(edit_button_); | |
332 layout->AddView(save_button_); | |
333 | |
334 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | |
335 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); | |
336 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); | |
337 | 351 |
338 AddChildView(bookmark_contents_view_); | 352 AddChildView(bookmark_contents_view_); |
339 } | 353 } |
340 | 354 |
341 // Private methods ------------------------------------------------------------- | 355 // Private methods ------------------------------------------------------------- |
342 | 356 |
343 BookmarkBubbleView::BookmarkBubbleView( | 357 BookmarkBubbleView::BookmarkBubbleView( |
344 views::View* anchor_view, | 358 views::View* anchor_view, |
345 bookmarks::BookmarkBubbleObserver* observer, | 359 bookmarks::BookmarkBubbleObserver* observer, |
346 std::unique_ptr<BubbleSyncPromoDelegate> delegate, | 360 std::unique_ptr<BubbleSyncPromoDelegate> delegate, |
347 Profile* profile, | 361 Profile* profile, |
348 const GURL& url, | 362 const GURL& url, |
349 bool newly_bookmarked) | 363 bool newly_bookmarked) |
350 : LocationBarBubbleDelegateView(anchor_view, nullptr), | 364 : LocationBarBubbleDelegateView(anchor_view, nullptr), |
351 observer_(observer), | 365 observer_(observer), |
352 delegate_(std::move(delegate)), | 366 delegate_(std::move(delegate)), |
353 profile_(profile), | 367 profile_(profile), |
354 url_(url), | 368 url_(url), |
355 newly_bookmarked_(newly_bookmarked), | 369 newly_bookmarked_(newly_bookmarked), |
356 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), | 370 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), |
357 BookmarkModelFactory::GetForBrowserContext(profile_) | 371 BookmarkModelFactory::GetForBrowserContext(profile_) |
358 ->GetMostRecentlyAddedUserNodeForURL(url)), | 372 ->GetMostRecentlyAddedUserNodeForURL(url)) { |
359 remove_button_(nullptr), | |
360 edit_button_(nullptr), | |
361 save_button_(nullptr), | |
362 name_field_(nullptr), | |
363 parent_combobox_(nullptr), | |
364 ios_promo_view_(nullptr), | |
365 footnote_view_(nullptr), | |
366 remove_bookmark_(false), | |
367 apply_edits_(true), | |
368 is_showing_ios_promotion_(false) { | |
369 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); | 373 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); |
370 } | 374 } |
371 | 375 |
372 base::string16 BookmarkBubbleView::GetBookmarkName() { | 376 base::string16 BookmarkBubbleView::GetBookmarkName() { |
373 BookmarkModel* bookmark_model = | 377 BookmarkModel* bookmark_model = |
374 BookmarkModelFactory::GetForBrowserContext(profile_); | 378 BookmarkModelFactory::GetForBrowserContext(profile_); |
375 const BookmarkNode* node = | 379 const BookmarkNode* node = |
376 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); | 380 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); |
377 if (node) | 381 if (node) |
378 return node->GetTitle(); | 382 return node->GetTitle(); |
379 else | 383 else |
380 NOTREACHED(); | 384 NOTREACHED(); |
381 return base::string16(); | 385 return base::string16(); |
382 } | 386 } |
383 | 387 |
384 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | |
385 if (sender == remove_button_) { | |
386 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
387 // Set this so we remove the bookmark after the window closes. | |
388 remove_bookmark_ = true; | |
389 apply_edits_ = false; | |
390 GetWidget()->Close(); | |
391 } else if (sender == edit_button_) { | |
392 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | |
393 ShowEditor(); | |
394 } else { | |
395 DCHECK_EQ(save_button_, sender); | |
396 #if defined(OS_WIN) | |
397 if (IsIOSPromotionEligible( | |
398 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { | |
399 ShowIOSPromotion( | |
400 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
401 } else { | |
402 GetWidget()->Close(); | |
403 } | |
404 #else | |
405 GetWidget()->Close(); | |
406 #endif | |
407 } | |
408 } | |
409 | |
410 void BookmarkBubbleView::ShowEditor() { | 388 void BookmarkBubbleView::ShowEditor() { |
411 const BookmarkNode* node = | 389 const BookmarkNode* node = |
412 BookmarkModelFactory::GetForBrowserContext(profile_) | 390 BookmarkModelFactory::GetForBrowserContext(profile_) |
413 ->GetMostRecentlyAddedUserNodeForURL(url_); | 391 ->GetMostRecentlyAddedUserNodeForURL(url_); |
414 gfx::NativeWindow native_parent = | 392 gfx::NativeWindow native_parent = |
415 anchor_widget() ? anchor_widget()->GetNativeWindow() | 393 anchor_widget() ? anchor_widget()->GetNativeWindow() |
416 : platform_util::GetTopLevel(parent_window()); | 394 : platform_util::GetTopLevel(parent_window()); |
417 DCHECK(native_parent); | 395 DCHECK(native_parent); |
418 | 396 |
419 Profile* profile = profile_; | 397 Profile* profile = profile_; |
(...skipping 30 matching lines...) Expand all Loading... | |
450 PrefService* prefs = profile_->GetPrefs(); | 428 PrefService* prefs = profile_->GetPrefs(); |
451 const browser_sync::ProfileSyncService* sync_service = | 429 const browser_sync::ProfileSyncService* sync_service = |
452 ProfileSyncServiceFactory::GetForProfile(profile_); | 430 ProfileSyncServiceFactory::GetForProfile(profile_); |
453 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, | 431 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, |
454 entry_point); | 432 entry_point); |
455 } | 433 } |
456 | 434 |
457 void BookmarkBubbleView::ShowIOSPromotion( | 435 void BookmarkBubbleView::ShowIOSPromotion( |
458 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 436 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
459 DCHECK(!is_showing_ios_promotion_); | 437 DCHECK(!is_showing_ios_promotion_); |
438 edit_button_->SetVisible(false); | |
460 // Hide the contents, but don't delete. Its child views are accessed in the | 439 // Hide the contents, but don't delete. Its child views are accessed in the |
461 // destructor if there are edits to apply. | 440 // destructor if there are edits to apply. |
462 bookmark_contents_view_->SetVisible(false); | 441 bookmark_contents_view_->SetVisible(false); |
463 delete footnote_view_; | 442 delete footnote_view_; |
464 footnote_view_ = nullptr; | 443 footnote_view_ = nullptr; |
465 is_showing_ios_promotion_ = true; | 444 is_showing_ios_promotion_ = true; |
466 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); | 445 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); |
467 AddChildView(ios_promo_view_); | 446 AddChildView(ios_promo_view_); |
468 GetWidget()->UpdateWindowIcon(); | 447 GetWidget()->UpdateWindowIcon(); |
469 GetWidget()->UpdateWindowTitle(); | 448 GetWidget()->UpdateWindowTitle(); |
470 // Resize the bubble so it has the same width as the parent bubble. | 449 GetDialogClientView()->UpdateDialogButtons(); |
471 ios_promo_view_->UpdateBubbleHeight(); | 450 SizeToContents(); |
472 } | 451 } |
473 #endif | 452 #endif |
OLD | NEW |