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> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "components/strings/grit/components_strings.h" | 28 #include "components/strings/grit/components_strings.h" |
29 #include "ui/accessibility/ax_node_data.h" | 29 #include "ui/accessibility/ax_node_data.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/events/keycodes/keyboard_codes.h" | 31 #include "ui/events/keycodes/keyboard_codes.h" |
32 #include "ui/views/bubble/bubble_frame_view.h" | 32 #include "ui/views/bubble/bubble_frame_view.h" |
33 #include "ui/views/controls/button/md_text_button.h" | 33 #include "ui/views/controls/button/md_text_button.h" |
34 #include "ui/views/controls/combobox/combobox.h" | 34 #include "ui/views/controls/combobox/combobox.h" |
35 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
36 #include "ui/views/controls/link.h" | 36 #include "ui/views/controls/link.h" |
37 #include "ui/views/controls/textfield/textfield.h" | 37 #include "ui/views/controls/textfield/textfield.h" |
| 38 #include "ui/views/layout/fill_layout.h" |
38 #include "ui/views/layout/grid_layout.h" | 39 #include "ui/views/layout/grid_layout.h" |
39 #include "ui/views/layout/layout_constants.h" | 40 #include "ui/views/layout/layout_constants.h" |
40 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
41 | 42 |
| 43 #if defined(OS_WIN) |
| 44 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 45 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" |
| 46 #include "components/browser_sync/profile_sync_service.h" |
| 47 #endif |
| 48 |
42 using base::UserMetricsAction; | 49 using base::UserMetricsAction; |
43 using bookmarks::BookmarkModel; | 50 using bookmarks::BookmarkModel; |
44 using bookmarks::BookmarkNode; | 51 using bookmarks::BookmarkNode; |
45 using views::ColumnSet; | 52 using views::ColumnSet; |
46 using views::GridLayout; | 53 using views::GridLayout; |
47 | 54 |
48 namespace { | 55 namespace { |
49 | 56 |
50 // This combobox prevents any lengthy content from stretching the bubble view. | 57 // This combobox prevents any lengthy content from stretching the bubble view. |
51 class UnsizedCombobox : public views::Combobox { | 58 class UnsizedCombobox : public views::Combobox { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 close_button_->SetIsDefault(true); | 171 close_button_->SetIsDefault(true); |
165 | 172 |
166 views::Label* combobox_label = new views::Label( | 173 views::Label* combobox_label = new views::Label( |
167 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 174 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
168 | 175 |
169 parent_combobox_ = new UnsizedCombobox(&parent_model_); | 176 parent_combobox_ = new UnsizedCombobox(&parent_model_); |
170 parent_combobox_->set_listener(this); | 177 parent_combobox_->set_listener(this); |
171 parent_combobox_->SetAccessibleName( | 178 parent_combobox_->SetAccessibleName( |
172 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); | 179 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); |
173 | 180 |
174 GridLayout* layout = new GridLayout(this); | 181 SetLayoutManager(new views::FillLayout); |
175 SetLayoutManager(layout); | 182 bookmark_details_view_ = base::MakeUnique<View>(); |
| 183 GridLayout* layout = new GridLayout(bookmark_details_view_.get()); |
| 184 bookmark_details_view_->SetLayoutManager(layout); |
176 | 185 |
177 // This column set is used for the labels and textfields as well as the | 186 // This column set is used for the labels and textfields as well as the |
178 // buttons at the bottom. | 187 // buttons at the bottom. |
179 const int cs_id = 0; | 188 const int cs_id = 0; |
180 ColumnSet* cs = layout->AddColumnSet(cs_id); | 189 ColumnSet* cs = layout->AddColumnSet(cs_id); |
181 cs->AddColumn(LayoutDelegate::Get()->GetControlLabelGridAlignment(), | 190 cs->AddColumn(LayoutDelegate::Get()->GetControlLabelGridAlignment(), |
182 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); | 191 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); |
183 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); | 192 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
184 | 193 |
185 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | 194 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
(...skipping 27 matching lines...) Expand all Loading... |
213 | 222 |
214 layout->StartRow(0, cs_id); | 223 layout->StartRow(0, cs_id); |
215 layout->SkipColumns(2); | 224 layout->SkipColumns(2); |
216 layout->AddView(remove_button_); | 225 layout->AddView(remove_button_); |
217 layout->AddView(edit_button_); | 226 layout->AddView(edit_button_); |
218 layout->AddView(close_button_); | 227 layout->AddView(close_button_); |
219 | 228 |
220 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 229 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
221 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); | 230 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); |
222 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); | 231 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); |
| 232 |
| 233 AddChildView(bookmark_details_view_.get()); |
| 234 } |
| 235 |
| 236 gfx::ImageSkia BookmarkBubbleView::GetWindowIcon() { |
| 237 #if defined(OS_WIN) |
| 238 if (is_showing_ios_promotion_) { |
| 239 return desktop_ios_promotion::GetPromoImage( |
| 240 GetNativeTheme()->GetSystemColor( |
| 241 ui::NativeTheme::kColorId_TextfieldDefaultColor)); |
| 242 } |
| 243 #endif |
| 244 return gfx::ImageSkia(); |
| 245 } |
| 246 |
| 247 bool BookmarkBubbleView::ShouldShowWindowIcon() const { |
| 248 return is_showing_ios_promotion_; |
223 } | 249 } |
224 | 250 |
225 base::string16 BookmarkBubbleView::GetWindowTitle() const { | 251 base::string16 BookmarkBubbleView::GetWindowTitle() const { |
| 252 #if defined(OS_WIN) |
| 253 if (is_showing_ios_promotion_) { |
| 254 return desktop_ios_promotion::GetPromoTitle( |
| 255 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); |
| 256 } |
| 257 #endif |
226 return l10n_util::GetStringUTF16(newly_bookmarked_ | 258 return l10n_util::GetStringUTF16(newly_bookmarked_ |
227 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED | 259 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED |
228 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK); | 260 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK); |
229 } | 261 } |
230 | 262 |
231 const char* BookmarkBubbleView::GetClassName() const { | 263 const char* BookmarkBubbleView::GetClassName() const { |
232 return "BookmarkBubbleView"; | 264 return "BookmarkBubbleView"; |
233 } | 265 } |
234 | 266 |
235 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 267 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
(...skipping 25 matching lines...) Expand all Loading... |
261 url_(url), | 293 url_(url), |
262 newly_bookmarked_(newly_bookmarked), | 294 newly_bookmarked_(newly_bookmarked), |
263 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), | 295 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), |
264 BookmarkModelFactory::GetForBrowserContext(profile_) | 296 BookmarkModelFactory::GetForBrowserContext(profile_) |
265 ->GetMostRecentlyAddedUserNodeForURL(url)), | 297 ->GetMostRecentlyAddedUserNodeForURL(url)), |
266 remove_button_(nullptr), | 298 remove_button_(nullptr), |
267 edit_button_(nullptr), | 299 edit_button_(nullptr), |
268 close_button_(nullptr), | 300 close_button_(nullptr), |
269 title_tf_(nullptr), | 301 title_tf_(nullptr), |
270 parent_combobox_(nullptr), | 302 parent_combobox_(nullptr), |
| 303 ios_promo_view_(nullptr), |
271 remove_bookmark_(false), | 304 remove_bookmark_(false), |
272 apply_edits_(true) {} | 305 apply_edits_(true), |
| 306 is_showing_ios_promotion_(false) {} |
273 | 307 |
274 base::string16 BookmarkBubbleView::GetTitle() { | 308 base::string16 BookmarkBubbleView::GetTitle() { |
275 BookmarkModel* bookmark_model = | 309 BookmarkModel* bookmark_model = |
276 BookmarkModelFactory::GetForBrowserContext(profile_); | 310 BookmarkModelFactory::GetForBrowserContext(profile_); |
277 const BookmarkNode* node = | 311 const BookmarkNode* node = |
278 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); | 312 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); |
279 if (node) | 313 if (node) |
280 return node->GetTitle(); | 314 return node->GetTitle(); |
281 else | 315 else |
282 NOTREACHED(); | 316 NOTREACHED(); |
(...skipping 24 matching lines...) Expand all Loading... |
307 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | 341 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); |
308 // Set this so we remove the bookmark after the window closes. | 342 // Set this so we remove the bookmark after the window closes. |
309 remove_bookmark_ = true; | 343 remove_bookmark_ = true; |
310 apply_edits_ = false; | 344 apply_edits_ = false; |
311 GetWidget()->Close(); | 345 GetWidget()->Close(); |
312 } else if (sender == edit_button_) { | 346 } else if (sender == edit_button_) { |
313 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 347 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
314 ShowEditor(); | 348 ShowEditor(); |
315 } else { | 349 } else { |
316 DCHECK_EQ(close_button_, sender); | 350 DCHECK_EQ(close_button_, sender); |
| 351 #if defined(OS_WIN) |
| 352 PrefService* prefs = profile_->GetPrefs(); |
| 353 const browser_sync::ProfileSyncService* sync_service = |
| 354 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 355 if (desktop_ios_promotion::IsEligibleForIOSPromotion( |
| 356 prefs, sync_service, |
| 357 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE)) { |
| 358 ShowIOSPromotion(); |
| 359 } else { |
| 360 GetWidget()->Close(); |
| 361 } |
| 362 #else |
317 GetWidget()->Close(); | 363 GetWidget()->Close(); |
| 364 #endif |
318 } | 365 } |
319 } | 366 } |
320 | 367 |
321 void BookmarkBubbleView::ShowEditor() { | 368 void BookmarkBubbleView::ShowEditor() { |
322 const BookmarkNode* node = | 369 const BookmarkNode* node = |
323 BookmarkModelFactory::GetForBrowserContext(profile_) | 370 BookmarkModelFactory::GetForBrowserContext(profile_) |
324 ->GetMostRecentlyAddedUserNodeForURL(url_); | 371 ->GetMostRecentlyAddedUserNodeForURL(url_); |
325 gfx::NativeWindow native_parent = | 372 gfx::NativeWindow native_parent = |
326 anchor_widget() ? anchor_widget()->GetNativeWindow() | 373 anchor_widget() ? anchor_widget()->GetNativeWindow() |
327 : platform_util::GetTopLevel(parent_window()); | 374 : platform_util::GetTopLevel(parent_window()); |
(...skipping 18 matching lines...) Expand all Loading... |
346 if (node) { | 393 if (node) { |
347 const base::string16 new_title = title_tf_->text(); | 394 const base::string16 new_title = title_tf_->text(); |
348 if (new_title != node->GetTitle()) { | 395 if (new_title != node->GetTitle()) { |
349 model->SetTitle(node, new_title); | 396 model->SetTitle(node, new_title); |
350 base::RecordAction( | 397 base::RecordAction( |
351 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 398 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
352 } | 399 } |
353 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 400 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
354 } | 401 } |
355 } | 402 } |
| 403 |
| 404 #if defined(OS_WIN) |
| 405 void BookmarkBubbleView::ShowIOSPromotion() { |
| 406 DCHECK(!is_showing_ios_promotion_); |
| 407 RemoveChildView(bookmark_details_view_.get()); |
| 408 is_showing_ios_promotion_ = true; |
| 409 ios_promo_view_ = new DesktopIOSPromotionBubbleView( |
| 410 profile_, desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); |
| 411 AddChildView(ios_promo_view_); |
| 412 GetWidget()->UpdateWindowIcon(); |
| 413 GetWidget()->UpdateWindowTitle(); |
| 414 SizeToContents(); |
| 415 } |
| 416 #endif |
OLD | NEW |