Chromium Code Reviews| 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 { |
| 52 public: | 59 public: |
| 53 explicit UnsizedCombobox(ui::ComboboxModel* model) : views::Combobox(model) {} | 60 explicit UnsizedCombobox(ui::ComboboxModel* model) : views::Combobox(model) {} |
| 54 ~UnsizedCombobox() override {} | 61 ~UnsizedCombobox() override {} |
| 55 | 62 |
| 56 gfx::Size GetPreferredSize() const override { | 63 gfx::Size GetPreferredSize() const override { |
| 57 return gfx::Size(0, views::Combobox::GetPreferredSize().height()); | 64 return gfx::Size(0, views::Combobox::GetPreferredSize().height()); |
| 58 } | 65 } |
| 59 | 66 |
| 60 private: | 67 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(UnsizedCombobox); | 68 DISALLOW_COPY_AND_ASSIGN(UnsizedCombobox); |
| 62 }; | 69 }; |
| 63 | |
| 64 } // namespace | 70 } // namespace |
| 65 | 71 |
| 66 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; | 72 BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; |
| 67 | 73 |
| 68 // static | 74 // static |
| 69 views::Widget* BookmarkBubbleView::ShowBubble( | 75 views::Widget* BookmarkBubbleView::ShowBubble( |
| 70 views::View* anchor_view, | 76 views::View* anchor_view, |
| 71 const gfx::Rect& anchor_rect, | 77 const gfx::Rect& anchor_rect, |
| 72 gfx::NativeView parent_window, | 78 gfx::NativeView parent_window, |
| 73 bookmarks::BookmarkBubbleObserver* observer, | 79 bookmarks::BookmarkBubbleObserver* observer, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 close_button_->SetIsDefault(true); | 170 close_button_->SetIsDefault(true); |
| 165 | 171 |
| 166 views::Label* combobox_label = new views::Label( | 172 views::Label* combobox_label = new views::Label( |
| 167 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 173 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
| 168 | 174 |
| 169 parent_combobox_ = new UnsizedCombobox(&parent_model_); | 175 parent_combobox_ = new UnsizedCombobox(&parent_model_); |
| 170 parent_combobox_->set_listener(this); | 176 parent_combobox_->set_listener(this); |
| 171 parent_combobox_->SetAccessibleName( | 177 parent_combobox_->SetAccessibleName( |
| 172 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); | 178 l10n_util::GetStringUTF16(IDS_BOOKMARK_AX_BUBBLE_FOLDER_TEXT)); |
| 173 | 179 |
| 174 GridLayout* layout = new GridLayout(this); | 180 SetLayoutManager(new views::FillLayout); |
| 175 SetLayoutManager(layout); | 181 bookmark_details_view_.reset(new View); |
|
sky
2017/03/30 20:30:17
Use base::MakeUnique (search for threads on chromi
mrefaat
2017/03/30 20:46:51
Done.
| |
| 182 GridLayout* layout = new GridLayout(bookmark_details_view_.get()); | |
| 183 bookmark_details_view_->SetLayoutManager(layout); | |
| 176 | 184 |
| 177 // This column set is used for the labels and textfields as well as the | 185 // This column set is used for the labels and textfields as well as the |
| 178 // buttons at the bottom. | 186 // buttons at the bottom. |
| 179 const int cs_id = 0; | 187 const int cs_id = 0; |
| 180 ColumnSet* cs = layout->AddColumnSet(cs_id); | 188 ColumnSet* cs = layout->AddColumnSet(cs_id); |
| 181 cs->AddColumn(LayoutDelegate::Get()->GetControlLabelGridAlignment(), | 189 cs->AddColumn(LayoutDelegate::Get()->GetControlLabelGridAlignment(), |
| 182 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); | 190 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); |
| 183 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); | 191 cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
| 184 | 192 |
| 185 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | 193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 213 | 221 |
| 214 layout->StartRow(0, cs_id); | 222 layout->StartRow(0, cs_id); |
| 215 layout->SkipColumns(2); | 223 layout->SkipColumns(2); |
| 216 layout->AddView(remove_button_); | 224 layout->AddView(remove_button_); |
| 217 layout->AddView(edit_button_); | 225 layout->AddView(edit_button_); |
| 218 layout->AddView(close_button_); | 226 layout->AddView(close_button_); |
| 219 | 227 |
| 220 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 228 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| 221 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); | 229 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); |
| 222 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); | 230 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); |
| 231 | |
| 232 AddChildView(bookmark_details_view_.get()); | |
| 233 } | |
| 234 | |
| 235 gfx::ImageSkia BookmarkBubbleView::GetWindowIcon() { | |
| 236 #if defined(OS_WIN) | |
| 237 if (is_showing_ios_promotion_) { | |
| 238 return desktop_ios_promotion::GetPromoImage( | |
| 239 GetNativeTheme()->GetSystemColor( | |
| 240 ui::NativeTheme::kColorId_TextfieldDefaultColor)); | |
| 241 } | |
| 242 #endif | |
| 243 return gfx::ImageSkia(); | |
| 244 } | |
| 245 | |
| 246 bool BookmarkBubbleView::ShouldShowWindowIcon() const { | |
| 247 return is_showing_ios_promotion_; | |
| 223 } | 248 } |
| 224 | 249 |
| 225 base::string16 BookmarkBubbleView::GetWindowTitle() const { | 250 base::string16 BookmarkBubbleView::GetWindowTitle() const { |
| 251 #if defined(OS_WIN) | |
| 252 if (is_showing_ios_promotion_) { | |
| 253 return desktop_ios_promotion::GetPromoTitle( | |
| 254 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
| 255 } | |
| 256 #endif | |
| 226 return l10n_util::GetStringUTF16(newly_bookmarked_ | 257 return l10n_util::GetStringUTF16(newly_bookmarked_ |
| 227 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED | 258 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED |
| 228 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK); | 259 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK); |
| 229 } | 260 } |
| 230 | 261 |
| 231 const char* BookmarkBubbleView::GetClassName() const { | 262 const char* BookmarkBubbleView::GetClassName() const { |
| 232 return "BookmarkBubbleView"; | 263 return "BookmarkBubbleView"; |
| 233 } | 264 } |
| 234 | 265 |
| 235 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { | 266 views::View* BookmarkBubbleView::GetInitiallyFocusedView() { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 261 url_(url), | 292 url_(url), |
| 262 newly_bookmarked_(newly_bookmarked), | 293 newly_bookmarked_(newly_bookmarked), |
| 263 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), | 294 parent_model_(BookmarkModelFactory::GetForBrowserContext(profile_), |
| 264 BookmarkModelFactory::GetForBrowserContext(profile_) | 295 BookmarkModelFactory::GetForBrowserContext(profile_) |
| 265 ->GetMostRecentlyAddedUserNodeForURL(url)), | 296 ->GetMostRecentlyAddedUserNodeForURL(url)), |
| 266 remove_button_(nullptr), | 297 remove_button_(nullptr), |
| 267 edit_button_(nullptr), | 298 edit_button_(nullptr), |
| 268 close_button_(nullptr), | 299 close_button_(nullptr), |
| 269 title_tf_(nullptr), | 300 title_tf_(nullptr), |
| 270 parent_combobox_(nullptr), | 301 parent_combobox_(nullptr), |
| 302 bookmark_details_view_(nullptr), | |
|
sky
2017/03/30 20:30:17
Remove this as bookmark_details_view_ is now a uni
mrefaat
2017/03/30 20:46:51
Done.
| |
| 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 RemoveChildView(bookmark_details_view_.get()); | |
|
sky
2017/03/30 20:30:17
DCHECK(!is_showing_ios_promotion_)
mrefaat
2017/03/30 20:46:51
Done.
| |
| 407 is_showing_ios_promotion_ = true; | |
| 408 ios_promo_view_ = new DesktopIOSPromotionBubbleView( | |
| 409 profile_, desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE); | |
| 410 AddChildView(ios_promo_view_); | |
| 411 GetWidget()->non_client_view()->ResetWindowControls(); | |
|
sky
2017/03/30 20:30:17
Why do you need the ResetWindowControls()?
mrefaat
2017/03/30 20:46:51
i thought because is use the control (Done) and th
| |
| 412 GetWidget()->UpdateWindowIcon(); | |
| 413 GetWidget()->UpdateWindowTitle(); | |
| 414 SizeToContents(); | |
| 415 } | |
| 416 #endif | |
| OLD | NEW |