Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc

Issue 2904333002: Reorder methods in BookmarkBubbleView. (Closed)
Patch Set: selfnit Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_); 123 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_);
124 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_); 124 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url_);
125 if (node) 125 if (node)
126 model->Remove(node); 126 model->Remove(node);
127 } 127 }
128 // |parent_combobox_| needs to be destroyed before |parent_model_| as it 128 // |parent_combobox_| needs to be destroyed before |parent_model_| as it
129 // uses |parent_model_| in its destructor. 129 // uses |parent_model_| in its destructor.
130 delete parent_combobox_; 130 delete parent_combobox_;
131 } 131 }
132 132
133 // views::WidgetDelegate -------------------------------------------------------
134
135 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
136 return title_tf_;
137 }
138
139 base::string16 BookmarkBubbleView::GetWindowTitle() const {
140 #if defined(OS_WIN)
141 if (is_showing_ios_promotion_) {
142 return desktop_ios_promotion::GetPromoTitle(
143 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE);
144 }
145 #endif
146 return l10n_util::GetStringUTF16(newly_bookmarked_
147 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED
148 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK);
149 }
150
151 gfx::ImageSkia BookmarkBubbleView::GetWindowIcon() {
152 #if defined(OS_WIN)
153 if (is_showing_ios_promotion_) {
154 return desktop_ios_promotion::GetPromoImage(
155 GetNativeTheme()->GetSystemColor(
156 ui::NativeTheme::kColorId_TextfieldDefaultColor));
157 }
158 #endif
159 return gfx::ImageSkia();
160 }
161
162 bool BookmarkBubbleView::ShouldShowWindowIcon() const {
163 return is_showing_ios_promotion_;
164 }
165
133 void BookmarkBubbleView::WindowClosing() { 166 void BookmarkBubbleView::WindowClosing() {
134 // We have to reset |bubble_| here, not in our destructor, because we'll be 167 // We have to reset |bubble_| here, not in our destructor, because we'll be
135 // destroyed asynchronously and the shown state will be checked before then. 168 // destroyed asynchronously and the shown state will be checked before then.
136 DCHECK_EQ(bookmark_bubble_, this); 169 DCHECK_EQ(bookmark_bubble_, this);
137 bookmark_bubble_ = NULL; 170 bookmark_bubble_ = NULL;
138 is_showing_ios_promotion_ = false; 171 is_showing_ios_promotion_ = false;
139 172
140 if (observer_) 173 if (observer_)
141 observer_->OnBookmarkBubbleHidden(); 174 observer_->OnBookmarkBubbleHidden();
142 } 175 }
143 176
177 // views::DialogDelegate -------------------------------------------------------
178
179 views::View* BookmarkBubbleView::CreateFootnoteView() {
180 #if defined(OS_WIN)
181 if (!is_showing_ios_promotion_ &&
182 IsIOSPromotionEligible(
183 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) {
184 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this);
185 return footnote_view_;
186 }
187 #endif
188 if (!SyncPromoUI::ShouldShowSyncPromo(profile_))
189 return nullptr;
190
191 base::RecordAction(UserMetricsAction("Signin_Impression_FromBookmarkBubble"));
192
193 footnote_view_ =
194 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK,
195 IDS_BOOKMARK_SYNC_PROMO_MESSAGE);
196 return footnote_view_;
197 }
198
199 // views::View -----------------------------------------------------------------
200
201 const char* BookmarkBubbleView::GetClassName() const {
202 return "BookmarkBubbleView";
203 }
204
144 bool BookmarkBubbleView::AcceleratorPressed( 205 bool BookmarkBubbleView::AcceleratorPressed(
145 const ui::Accelerator& accelerator) { 206 const ui::Accelerator& accelerator) {
146 ui::KeyboardCode key_code = accelerator.key_code(); 207 ui::KeyboardCode key_code = accelerator.key_code();
147 if (key_code == ui::VKEY_RETURN) { 208 if (key_code == ui::VKEY_RETURN) {
148 HandleButtonPressed(close_button_); 209 HandleButtonPressed(close_button_);
149 return true; 210 return true;
150 } 211 }
151 if (key_code == ui::VKEY_E && accelerator.IsAltDown()) { 212 if (key_code == ui::VKEY_E && accelerator.IsAltDown()) {
152 HandleButtonPressed(edit_button_); 213 HandleButtonPressed(edit_button_);
153 return true; 214 return true;
154 } 215 }
155 if (key_code == ui::VKEY_R && accelerator.IsAltDown()) { 216 if (key_code == ui::VKEY_R && accelerator.IsAltDown()) {
156 HandleButtonPressed(remove_button_); 217 HandleButtonPressed(remove_button_);
157 return true; 218 return true;
158 } 219 }
159 220
160 return LocationBarBubbleDelegateView::AcceleratorPressed(accelerator); 221 return LocationBarBubbleDelegateView::AcceleratorPressed(accelerator);
161 } 222 }
162 223
224 void BookmarkBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
225 LocationBarBubbleDelegateView::GetAccessibleNodeData(node_data);
226 node_data->SetName(l10n_util::GetStringUTF8(
227 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED
228 : IDS_BOOKMARK_AX_BUBBLE_PAGE_BOOKMARK));
229 }
230
231 // views::ButtonListener -------------------------------------------------------
232
233 void BookmarkBubbleView::ButtonPressed(views::Button* sender,
234 const ui::Event& event) {
235 HandleButtonPressed(sender);
236 }
237
238 // views::ComboboxListener -----------------------------------------------------
239
240 void BookmarkBubbleView::OnPerformAction(views::Combobox* combobox) {
241 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) {
242 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox"));
243 ShowEditor();
244 }
245 }
246
247 // DesktopIOSPromotionFootnoteDelegate -----------------------------------------
248
249 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() {
250 #if defined(OS_WIN)
251 ShowIOSPromotion(
252 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE);
253 #endif
254 }
255
256 // views::BubbleDialogDelegateView ---------------------------------------------
257
163 void BookmarkBubbleView::Init() { 258 void BookmarkBubbleView::Init() {
164 remove_button_ = views::MdTextButton::CreateSecondaryUiButton( 259 remove_button_ = views::MdTextButton::CreateSecondaryUiButton(
165 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); 260 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK));
166 261
167 edit_button_ = views::MdTextButton::CreateSecondaryUiButton( 262 edit_button_ = views::MdTextButton::CreateSecondaryUiButton(
168 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); 263 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS));
169 264
170 close_button_ = views::MdTextButton::CreateSecondaryUiButton( 265 close_button_ = views::MdTextButton::CreateSecondaryUiButton(
171 this, l10n_util::GetStringUTF16(IDS_DONE)); 266 this, l10n_util::GetStringUTF16(IDS_DONE));
172 close_button_->SetIsDefault(true); 267 close_button_->SetIsDefault(true);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 layout->AddView(edit_button_); 329 layout->AddView(edit_button_);
235 layout->AddView(close_button_); 330 layout->AddView(close_button_);
236 331
237 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 332 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
238 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN)); 333 AddAccelerator(ui::Accelerator(ui::VKEY_E, ui::EF_ALT_DOWN));
239 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)); 334 AddAccelerator(ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN));
240 335
241 AddChildView(bookmark_details_view_.get()); 336 AddChildView(bookmark_details_view_.get());
242 } 337 }
243 338
244 gfx::ImageSkia BookmarkBubbleView::GetWindowIcon() { 339 // Private methods -------------------------------------------------------------
245 #if defined(OS_WIN)
246 if (is_showing_ios_promotion_) {
247 return desktop_ios_promotion::GetPromoImage(
248 GetNativeTheme()->GetSystemColor(
249 ui::NativeTheme::kColorId_TextfieldDefaultColor));
250 }
251 #endif
252 return gfx::ImageSkia();
253 }
254
255 bool BookmarkBubbleView::ShouldShowWindowIcon() const {
256 return is_showing_ios_promotion_;
257 }
258
259 base::string16 BookmarkBubbleView::GetWindowTitle() const {
260 #if defined(OS_WIN)
261 if (is_showing_ios_promotion_) {
262 return desktop_ios_promotion::GetPromoTitle(
263 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE);
264 }
265 #endif
266 return l10n_util::GetStringUTF16(newly_bookmarked_
267 ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED
268 : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK);
269 }
270
271 const char* BookmarkBubbleView::GetClassName() const {
272 return "BookmarkBubbleView";
273 }
274
275 views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
276 return title_tf_;
277 }
278
279 views::View* BookmarkBubbleView::CreateFootnoteView() {
280 #if defined(OS_WIN)
281 if (!is_showing_ios_promotion_ &&
282 IsIOSPromotionEligible(
283 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_FOOTNOTE)) {
284 footnote_view_ = new DesktopIOSPromotionFootnoteView(profile_, this);
285 return footnote_view_;
286 }
287 #endif
288 if (!SyncPromoUI::ShouldShowSyncPromo(profile_))
289 return nullptr;
290
291 base::RecordAction(
292 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble"));
293
294 footnote_view_ =
295 new BubbleSyncPromoView(delegate_.get(), IDS_BOOKMARK_SYNC_PROMO_LINK,
296 IDS_BOOKMARK_SYNC_PROMO_MESSAGE);
297 return footnote_view_;
298 }
299 340
300 BookmarkBubbleView::BookmarkBubbleView( 341 BookmarkBubbleView::BookmarkBubbleView(
301 views::View* anchor_view, 342 views::View* anchor_view,
302 bookmarks::BookmarkBubbleObserver* observer, 343 bookmarks::BookmarkBubbleObserver* observer,
303 std::unique_ptr<BubbleSyncPromoDelegate> delegate, 344 std::unique_ptr<BubbleSyncPromoDelegate> delegate,
304 Profile* profile, 345 Profile* profile,
305 const GURL& url, 346 const GURL& url,
306 bool newly_bookmarked) 347 bool newly_bookmarked)
307 : LocationBarBubbleDelegateView(anchor_view, nullptr), 348 : LocationBarBubbleDelegateView(anchor_view, nullptr),
308 observer_(observer), 349 observer_(observer),
(...skipping 22 matching lines...) Expand all
331 BookmarkModelFactory::GetForBrowserContext(profile_); 372 BookmarkModelFactory::GetForBrowserContext(profile_);
332 const BookmarkNode* node = 373 const BookmarkNode* node =
333 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_); 374 bookmark_model->GetMostRecentlyAddedUserNodeForURL(url_);
334 if (node) 375 if (node)
335 return node->GetTitle(); 376 return node->GetTitle();
336 else 377 else
337 NOTREACHED(); 378 NOTREACHED();
338 return base::string16(); 379 return base::string16();
339 } 380 }
340 381
341 void BookmarkBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
342 LocationBarBubbleDelegateView::GetAccessibleNodeData(node_data);
343 node_data->SetName(l10n_util::GetStringUTF8(
344 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED
345 : IDS_BOOKMARK_AX_BUBBLE_PAGE_BOOKMARK));
346 }
347
348 void BookmarkBubbleView::ButtonPressed(views::Button* sender,
349 const ui::Event& event) {
350 HandleButtonPressed(sender);
351 }
352
353 void BookmarkBubbleView::OnPerformAction(views::Combobox* combobox) {
354 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) {
355 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox"));
356 ShowEditor();
357 }
358 }
359
360 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { 382 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) {
361 if (sender == remove_button_) { 383 if (sender == remove_button_) {
362 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); 384 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
363 // Set this so we remove the bookmark after the window closes. 385 // Set this so we remove the bookmark after the window closes.
364 remove_bookmark_ = true; 386 remove_bookmark_ = true;
365 apply_edits_ = false; 387 apply_edits_ = false;
366 GetWidget()->Close(); 388 GetWidget()->Close();
367 } else if (sender == edit_button_) { 389 } else if (sender == edit_button_) {
368 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); 390 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
369 ShowEditor(); 391 ShowEditor();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 const base::string16 new_title = title_tf_->text(); 434 const base::string16 new_title = title_tf_->text();
413 if (new_title != node->GetTitle()) { 435 if (new_title != node->GetTitle()) {
414 model->SetTitle(node, new_title); 436 model->SetTitle(node, new_title);
415 base::RecordAction( 437 base::RecordAction(
416 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 438 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
417 } 439 }
418 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); 440 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index());
419 } 441 }
420 } 442 }
421 443
422 void BookmarkBubbleView::OnIOSPromotionFootnoteLinkClicked() {
423 #if defined(OS_WIN)
424 ShowIOSPromotion(
425 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE);
426 #endif
427 }
428
429 #if defined(OS_WIN) 444 #if defined(OS_WIN)
430 445
431 bool BookmarkBubbleView::IsIOSPromotionEligible( 446 bool BookmarkBubbleView::IsIOSPromotionEligible(
432 desktop_ios_promotion::PromotionEntryPoint entry_point) { 447 desktop_ios_promotion::PromotionEntryPoint entry_point) {
433 PrefService* prefs = profile_->GetPrefs(); 448 PrefService* prefs = profile_->GetPrefs();
434 const browser_sync::ProfileSyncService* sync_service = 449 const browser_sync::ProfileSyncService* sync_service =
435 ProfileSyncServiceFactory::GetForProfile(profile_); 450 ProfileSyncServiceFactory::GetForProfile(profile_);
436 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service, 451 return desktop_ios_promotion::IsEligibleForIOSPromotion(prefs, sync_service,
437 entry_point); 452 entry_point);
438 } 453 }
439 454
440 void BookmarkBubbleView::ShowIOSPromotion( 455 void BookmarkBubbleView::ShowIOSPromotion(
441 desktop_ios_promotion::PromotionEntryPoint entry_point) { 456 desktop_ios_promotion::PromotionEntryPoint entry_point) {
442 DCHECK(!is_showing_ios_promotion_); 457 DCHECK(!is_showing_ios_promotion_);
443 RemoveChildView(bookmark_details_view_.get()); 458 RemoveChildView(bookmark_details_view_.get());
444 delete footnote_view_; 459 delete footnote_view_;
445 footnote_view_ = nullptr; 460 footnote_view_ = nullptr;
446 is_showing_ios_promotion_ = true; 461 is_showing_ios_promotion_ = true;
447 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point); 462 ios_promo_view_ = new DesktopIOSPromotionBubbleView(profile_, entry_point);
448 AddChildView(ios_promo_view_); 463 AddChildView(ios_promo_view_);
449 GetWidget()->UpdateWindowIcon(); 464 GetWidget()->UpdateWindowIcon();
450 GetWidget()->UpdateWindowTitle(); 465 GetWidget()->UpdateWindowTitle();
451 // Resize the bubble so it has the same width as the parent bubble. 466 // Resize the bubble so it has the same width as the parent bubble.
452 ios_promo_view_->UpdateBubbleHeight(); 467 ios_promo_view_->UpdateBubbleHeight();
453 } 468 }
454 #endif 469 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698