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 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) | |
139 ? IDS_DONE | |
140 : IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK); | |
133 } | 141 } |
134 | 142 |
135 // views::WidgetDelegate ------------------------------------------------------- | 143 // views::WidgetDelegate ------------------------------------------------------- |
136 | 144 |
137 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 145 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
138 return name_field_; | 146 return name_field_; |
139 } | 147 } |
140 | 148 |
141 base::string16 BookmarkBubbleView::GetWindowTitle() const { | 149 base::string16 BookmarkBubbleView::GetWindowTitle() const { |
142 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
(...skipping 28 matching lines...) Expand all Loading... | |
171 DCHECK_EQ(bookmark_bubble_, this); | 179 DCHECK_EQ(bookmark_bubble_, this); |
172 bookmark_bubble_ = NULL; | 180 bookmark_bubble_ = NULL; |
173 is_showing_ios_promotion_ = false; | 181 is_showing_ios_promotion_ = false; |
174 | 182 |
175 if (observer_) | 183 if (observer_) |
176 observer_->OnBookmarkBubbleHidden(); | 184 observer_->OnBookmarkBubbleHidden(); |
177 } | 185 } |
178 | 186 |
179 // views::DialogDelegate ------------------------------------------------------- | 187 // views::DialogDelegate ------------------------------------------------------- |
180 | 188 |
189 views::View* BookmarkBubbleView::CreateExtraView() { | |
190 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( | |
191 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | |
192 edit_button_->AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); | |
193 return edit_button_; | |
194 } | |
195 | |
196 bool BookmarkBubbleView::GetExtraViewPadding(int* padding) { | |
197 *padding = ChromeLayoutProvider::Get()->GetDistanceMetric( | |
198 DISTANCE_UNRELATED_CONTROL_HORIZONTAL_LARGE); | |
199 return true; | |
200 } | |
201 | |
181 views::View* BookmarkBubbleView::CreateFootnoteView() { | 202 views::View* BookmarkBubbleView::CreateFootnoteView() { |
182 #if defined(OS_WIN) | 203 #if defined(OS_WIN) |
183 if (!is_showing_ios_promotion_ && | 204 if (!is_showing_ios_promotion_ && |
184 IsIOSPromotionEligible( | 205 IsIOSPromotionEligible( |
185 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) { | 206 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) { |
186 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this); | 207 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this); |
187 return footnote_view_; | 208 return footnote_view_; |
188 } | 209 } |
189 #endif | 210 #endif |
190 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) | 211 if (!SyncPromoUI::ShouldShowSyncPromo(profile_)) |
191 return nullptr; | 212 return nullptr; |
192 | 213 |
193 base::RecordAction(UserMetricsAction("Signin_Impression_FromBookmarkBubble")); | 214 base::RecordAction(UserMetricsAction("Signin_Impression_FromBookmarkBubble")); |
194 | 215 |
195 footnote_view_ = | 216 footnote_view_ = |
196 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, | 217 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK, |
197 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); | 218 IDS_BOOKMARK_SYNC_PROMO_MESSAGE); |
198 return footnote_view_; | 219 return footnote_view_; |
199 } | 220 } |
200 | 221 |
222 bool BookmarkBubbleView::Cancel() { | |
223 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
224 // Set this so we remove the bookmark after the window closes. | |
225 remove_bookmark_ = true; | |
226 apply_edits_ = false; | |
227 return true; | |
228 } | |
229 | |
230 bool BookmarkBubbleView::Accept() { | |
231 #if defined(OS_WIN) | |
232 using desktop_ios_promotion::PromotionEntryPoint; | |
233 if (IsIOSPromotionEligible(PromotionEntryPoint::BOOKMARKS_BUBBLE)) { | |
234 ShowIOSPromotion(PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
235 return false; | |
236 } | |
237 #endif | |
238 return true; | |
239 } | |
240 | |
241 bool BookmarkBubbleView::Close() { | |
242 // Allow closing when activation lost. Default would call Accept(). | |
243 return true; | |
244 } | |
245 | |
246 void BookmarkBubbleView::UpdateButton(views::LabelButton* button, | |
247 ui::DialogButton type) { | |
248 LocationBarBubbleDelegateView::UpdateButton(button, type); | |
249 if (type == ui::DIALOG_BUTTON_CANCEL) | |
250 button->AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); | |
251 } | |
252 | |
201 // views::View ----------------------------------------------------------------- | 253 // views::View ----------------------------------------------------------------- |
202 | 254 |
203 const char* BookmarkBubbleView::GetClassName() const { | 255 const char* BookmarkBubbleView::GetClassName() const { |
204 return "BookmarkBubbleView"; | 256 return "BookmarkBubbleView"; |
205 } | 257 } |
206 | 258 |
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) { | 259 void BookmarkBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
227 LocationBarBubbleDelegateView::GetAccessibleNodeData(node_data); | 260 LocationBarBubbleDelegateView::GetAccessibleNodeData(node_data); |
228 node_data->SetName(l10n_util::GetStringUTF8( | 261 node_data->SetName(l10n_util::GetStringUTF8( |
229 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED | 262 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED |
230 : IDS_BOOKMARK_AX_BUBBLE_PAGE_BOOKMARK)); | 263 : IDS_BOOKMARK_AX_BUBBLE_PAGE_BOOKMARK)); |
231 } | 264 } |
232 | 265 |
233 // views::ButtonListener ------------------------------------------------------- | 266 // views::ButtonListener ------------------------------------------------------- |
234 | 267 |
235 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 268 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
236 const ui::Event& event) { | 269 const ui::Event& event) { |
237 HandleButtonPressed(sender); | 270 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
271 ShowEditor(); | |
238 } | 272 } |
239 | 273 |
240 // views::ComboboxListener ----------------------------------------------------- | 274 // views::ComboboxListener ----------------------------------------------------- |
241 | 275 |
242 void BookmarkBubbleView::OnPerformAction(views::Combobox* combobox) { | 276 void BookmarkBubbleView::OnPerformAction(views::Combobox* combobox) { |
243 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 277 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
244 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 278 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
245 ShowEditor(); | 279 ShowEditor(); |
246 } | 280 } |
247 } | 281 } |
248 | 282 |
249 // DesktopIOSPromotionFootnoteDelegate ----------------------------------------- | 283 // DesktopIOSPromotionFootnoteDelegate ----------------------------------------- |
250 | 284 |
251 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() { | 285 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() { |
252 #if defined(OS_WIN) | 286 #if defined(OS_WIN) |
253 ShowIOSPromotion( | 287 ShowIOSPromotion( |
254 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE); | 288 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE); |
255 #endif | 289 #endif |
256 } | 290 } |
257 | 291 |
258 // views::BubbleDialogDelegateView --------------------------------------------- | 292 // views::BubbleDialogDelegateView --------------------------------------------- |
259 | 293 |
260 void BookmarkBubbleView::Init() { | 294 void BookmarkBubbleView::Init() { |
261 remove_button_ = views::MdTextButton::CreateSecondaryUiButton( | 295 using views::GridLayout; |
262 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | |
263 | 296 |
264 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( | 297 SetLayoutManager(new views::FillLayout()); |
265 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 298 bookmark_contents_view_ = new views::View(); |
299 GridLayout* layout = new GridLayout(bookmark_contents_view_); | |
300 bookmark_contents_view_->SetLayoutManager(layout); | |
266 | 301 |
267 save_button_ = views::MdTextButton::CreateSecondaryUiButton( | 302 // This column set is used for the labels and textfields. |
268 this, l10n_util::GetStringUTF16(IDS_DONE)); | 303 constexpr int kColumnId = 0; |
269 save_button_->SetIsDefault(true); | 304 constexpr float kFixed = 0.f; |
305 constexpr float kStretchy = 1.f; | |
306 views::ColumnSet* cs = layout->AddColumnSet(kColumnId); | |
307 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | |
270 | 308 |
309 cs->AddColumn(provider->GetControlLabelGridAlignment(), GridLayout::CENTER, | |
310 kFixed, GridLayout::USE_PREF, 0, 0); | |
311 cs->AddPaddingColumn(kFixed, provider->GetDistanceMetric( | |
312 DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); | |
313 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, kStretchy, | |
314 GridLayout::USE_PREF, 0, 0); | |
315 | |
316 layout->StartRow(kFixed, kColumnId); | |
317 views::Label* label = new views::Label( | |
318 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_NAME_LABEL)); | |
319 layout->AddView(label); | |
320 | |
321 name_field_ = new views::Textfield(); | |
322 name_field_->SetText(GetBookmarkName()); | |
323 name_field_->SetAccessibleName( | |
324 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_NAME_LABEL)); | |
325 layout->AddView(name_field_); | |
326 | |
327 layout->StartRowWithPadding( | |
328 kFixed, kColumnId, kFixed, | |
329 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)); | |
271 views::Label* combobox_label = new views::Label( | 330 views::Label* combobox_label = new views::Label( |
272 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 331 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_LABEL)); |
332 layout->AddView(combobox_label); | |
273 | 333 |
274 parent_combobox_ = new UnsizedCombobox(&parent_model_); | 334 parent_combobox_ = new UnsizedCombobox(&parent_model_); |
275 parent_combobox_->set_listener(this); | 335 parent_combobox_->set_listener(this); |
276 parent_combobox_->SetAccessibleName( | 336 parent_combobox_->SetAccessibleName( |
277 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); | 337 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_LABEL)); |
338 layout->AddView(parent_combobox_); | |
278 | 339 |
279 SetLayoutManager(new views::FillLayout); | 340 // TODO(tapted): BubbleDialogDelegateView should do this by default. |
280 bookmark_contents_view_ = new views::View(); | 341 set_button_row_insets(gfx::Insets( |
281 GridLayout* layout = new GridLayout(bookmark_contents_view_); | 342 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_VERTICAL), 0, 0, |
Peter Kasting
2017/05/31 05:45:46
I don't think we want to do this, as it makes bubb
tapted
2017/05/31 05:54:27
Done.
| |
282 bookmark_contents_view_->SetLayoutManager(layout); | 343 0)); |
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 | |
318 layout->AddPaddingRow( | |
319 0, provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).top()); | |
320 | |
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 | 344 |
338 AddChildView(bookmark_contents_view_); | 345 AddChildView(bookmark_contents_view_); |
339 } | 346 } |
340 | 347 |
341 // Private methods ------------------------------------------------------------- | 348 // Private methods ------------------------------------------------------------- |
342 | 349 |
343 BookmarkBubbleView::BookmarkBubbleView( | 350 BookmarkBubbleView::BookmarkBubbleView( |
344 views::View* anchor_view, | 351 views::View* anchor_view, |
345 bookmarks::BookmarkBubbleObserver* observer, | 352 bookmarks::BookmarkBubbleObserver* observer, |
346 std::unique_ptr<BubbleSyncPromoDelegate> delegate, | 353 std::unique_ptr<BubbleSyncPromoDelegate> delegate, |
347 Profile* profile, | 354 Profile* profile, |
348 const GURL& url, | 355 const GURL& url, |
349 bool newly_bookmarked) | 356 bool newly_bookmarked) |
350 : LocationBarBubbleDelegateView(anchor_view, nullptr), | 357 : LocationBarBubbleDelegateView(anchor_view, nullptr), |
351 observer_(observer), | 358 observer_(observer), |
352 delegate_(std::move(delegate)), | 359 delegate_(std::move(delegate)), |
353 profile_(profile), | 360 profile_(profile), |
354 url_(url), | 361 url_(url), |
355 newly_bookmarked_(newly_bookmarked), | 362 newly_bookmarked_(newly_bookmarked), |
356 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), | 363 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), |
357 BookmarkModelFactory::GetForBrowserContext(profile_) | 364 BookmarkModelFactory::GetForBrowserContext(profile_) |
358 ->GetMostRecentlyAddedUserNodeForURL(url)), | 365 ->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); | 366 chrome::RecordDialogCreation(chrome::DialogIdentifier::BOOKMARK); |
370 } | 367 } |
371 | 368 |
372 base::string16 BookmarkBubbleView::GetBookmarkName() { | 369 base::string16 BookmarkBubbleView::GetBookmarkName() { |
373 BookmarkModel* bookmark_model = | 370 BookmarkModel* bookmark_model = |
374 BookmarkModelFactory::GetForBrowserContext(profile_); | 371 BookmarkModelFactory::GetForBrowserContext(profile_); |
375 const BookmarkNode* node = | 372 const BookmarkNode* node = |
376 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); | 373 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); |
377 if (node) | 374 if (node) |
378 return node->GetTitle(); | 375 return node->GetTitle(); |
379 else | 376 else |
380 NOTREACHED(); | 377 NOTREACHED(); |
381 return base::string16(); | 378 return base::string16(); |
382 } | 379 } |
383 | 380 |
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() { | 381 void BookmarkBubbleView::ShowEditor() { |
411 const BookmarkNode* node = | 382 const BookmarkNode* node = |
412 BookmarkModelFactory::GetForBrowserContext(profile_) | 383 BookmarkModelFactory::GetForBrowserContext(profile_) |
413 ->GetMostRecentlyAddedUserNodeForURL(url_); | 384 ->GetMostRecentlyAddedUserNodeForURL(url_); |
414 gfx::NativeWindow native_parent = | 385 gfx::NativeWindow native_parent = |
415 anchor_widget() ? anchor_widget()->GetNativeWindow() | 386 anchor_widget() ? anchor_widget()->GetNativeWindow() |
416 : platform_util::GetTopLevel(parent_window()); | 387 : platform_util::GetTopLevel(parent_window()); |
417 DCHECK(native_parent); | 388 DCHECK(native_parent); |
418 | 389 |
419 Profile* profile = profile_; | 390 Profile* profile = profile_; |
(...skipping 30 matching lines...) Expand all Loading... | |
450 PrefService* prefs = profile_->GetPrefs(); | 421 PrefService* prefs = profile_->GetPrefs(); |
451 const browser_sync::ProfileSyncService* sync_service = | 422 const browser_sync::ProfileSyncService* sync_service = |
452 ProfileSyncServiceFactory::GetForProfile(profile_); | 423 ProfileSyncServiceFactory::GetForProfile(profile_); |
453 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, | 424 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, |
454 entry_point); | 425 entry_point); |
455 } | 426 } |
456 | 427 |
457 void BookmarkBubbleView::ShowIOSPromotion( | 428 void BookmarkBubbleView::ShowIOSPromotion( |
458 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 429 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
459 DCHECK(!is_showing_ios_promotion_); | 430 DCHECK(!is_showing_ios_promotion_); |
431 edit_button_->SetVisible(false); | |
460 // Hide the contents, but don't delete. Its child views are accessed in the | 432 // Hide the contents, but don't delete. Its child views are accessed in the |
461 // destructor if there are edits to apply. | 433 // destructor if there are edits to apply. |
462 bookmark_contents_view_->SetVisible(false); | 434 bookmark_contents_view_->SetVisible(false); |
463 delete footnote_view_; | 435 delete footnote_view_; |
464 footnote_view_ = nullptr; | 436 footnote_view_ = nullptr; |
465 is_showing_ios_promotion_ = true; | 437 is_showing_ios_promotion_ = true; |
466 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); | 438 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); |
467 AddChildView(ios_promo_view_); | 439 AddChildView(ios_promo_view_); |
468 GetWidget()->UpdateWindowIcon(); | 440 GetWidget()->UpdateWindowIcon(); |
469 GetWidget()->UpdateWindowTitle(); | 441 GetWidget()->UpdateWindowTitle(); |
470 // Resize the bubble so it has the same width as the parent bubble. | 442 GetDialogClientView()->UpdateDialogButtons(); |
471 ios_promo_view_->UpdateBubbleHeight(); | 443 SizeToContents(); |
472 } | 444 } |
473 #endif | 445 #endif |
OLD | NEW |