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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm

Issue 151283006: Mac OS X: Show the Translate icon on Omnibox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue-307352-translate-bubble-2
Patch Set: Use kAnimateNone Created 6 years, 9 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h"
15 #import "chrome/browser/app_controller_mac.h" 16 #import "chrome/browser/app_controller_mac.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/command_updater.h" 18 #include "chrome/browser/command_updater.h"
18 #include "chrome/browser/defaults.h" 19 #include "chrome/browser/defaults.h"
19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 20 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
20 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 21 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
21 #include "chrome/browser/extensions/extension_action.h" 22 #include "chrome/browser/extensions/extension_action.h"
22 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/location_bar_controller.h" 24 #include "chrome/browser/extensions/location_bar_controller.h"
24 #include "chrome/browser/extensions/tab_helper.h" 25 #include "chrome/browser/extensions/tab_helper.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/search/instant_service.h" 27 #include "chrome/browser/search/instant_service.h"
27 #include "chrome/browser/search/instant_service_factory.h" 28 #include "chrome/browser/search/instant_service_factory.h"
28 #include "chrome/browser/search/search.h" 29 #include "chrome/browser/search/search.h"
29 #include "chrome/browser/search_engines/template_url.h" 30 #include "chrome/browser/search_engines/template_url.h"
30 #include "chrome/browser/search_engines/template_url_service.h" 31 #include "chrome/browser/search_engines/template_url_service.h"
31 #include "chrome/browser/search_engines/template_url_service_factory.h" 32 #include "chrome/browser/search_engines/template_url_service_factory.h"
33 #include "chrome/browser/translate/translate_tab_helper.h"
32 #include "chrome/browser/ui/browser_instant_controller.h" 34 #include "chrome/browser/ui/browser_instant_controller.h"
33 #include "chrome/browser/ui/browser_list.h" 35 #include "chrome/browser/ui/browser_list.h"
34 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " 36 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
35 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 37 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
36 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" 38 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h"
37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 39 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 40 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
39 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" 41 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
40 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" 42 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h"
41 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h " 43 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h "
42 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" 44 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
43 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" 45 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
44 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" 46 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h"
45 #import "chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h" 47 #import "chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h"
46 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" 48 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h"
47 #import "chrome/browser/ui/cocoa/location_bar/search_button_decoration.h" 49 #import "chrome/browser/ui/cocoa/location_bar/search_button_decoration.h"
48 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" 50 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
49 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 51 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
52 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h"
50 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" 53 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
51 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 54 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
52 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 55 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
53 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 56 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
54 #include "chrome/browser/ui/omnibox/location_bar_util.h" 57 #include "chrome/browser/ui/omnibox/location_bar_util.h"
55 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" 58 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h"
56 #include "chrome/browser/ui/tabs/tab_strip_model.h" 59 #include "chrome/browser/ui/tabs/tab_strip_model.h"
57 #include "chrome/browser/ui/toolbar/toolbar_model.h" 60 #include "chrome/browser/ui/toolbar/toolbar_model.h"
58 #include "chrome/browser/ui/zoom/zoom_controller.h" 61 #include "chrome/browser/ui/zoom/zoom_controller.h"
59 #include "chrome/common/chrome_switches.h" 62 #include "chrome/common/chrome_switches.h"
60 #include "chrome/common/pref_names.h" 63 #include "chrome/common/pref_names.h"
64 #include "components/translate/core/browser/language_state.h"
61 #include "content/public/browser/notification_service.h" 65 #include "content/public/browser/notification_service.h"
62 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
63 #include "extensions/browser/extension_system.h" 67 #include "extensions/browser/extension_system.h"
64 #include "extensions/common/extension.h" 68 #include "extensions/common/extension.h"
65 #include "extensions/common/permissions/permissions_data.h" 69 #include "extensions/common/permissions/permissions_data.h"
66 #include "grit/generated_resources.h" 70 #include "grit/generated_resources.h"
67 #include "grit/theme_resources.h" 71 #include "grit/theme_resources.h"
68 #include "net/base/net_util.h" 72 #include "net/base/net_util.h"
69 #include "skia/ext/skia_utils_mac.h" 73 #include "skia/ext/skia_utils_mac.h"
70 #import "ui/base/cocoa/cocoa_base_utils.h" 74 #import "ui/base/cocoa/cocoa_base_utils.h"
(...skipping 29 matching lines...) Expand all
100 104
101 // NOTE: Can't DISALLOW_COPY_AND_ASSIGN as we pass this object by value to 105 // NOTE: Can't DISALLOW_COPY_AND_ASSIGN as we pass this object by value to
102 // std::stable_partition(). 106 // std::stable_partition().
103 }; 107 };
104 108
105 } 109 }
106 110
107 // TODO(shess): This code is mostly copied from the gtk 111 // TODO(shess): This code is mostly copied from the gtk
108 // implementation. Make sure it's all appropriate and flesh it out. 112 // implementation. Make sure it's all appropriate and flesh it out.
109 113
110 LocationBarViewMac::LocationBarViewMac( 114 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
111 AutocompleteTextField* field, 115 CommandUpdater* command_updater,
112 CommandUpdater* command_updater, 116 Profile* profile,
113 Profile* profile, 117 Browser* browser)
114 Browser* browser)
115 : LocationBar(profile), 118 : LocationBar(profile),
116 OmniboxEditController(command_updater), 119 OmniboxEditController(command_updater),
117 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 120 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
118 field_(field), 121 field_(field),
119 location_icon_decoration_(new LocationIconDecoration(this)), 122 location_icon_decoration_(new LocationIconDecoration(this)),
120 selected_keyword_decoration_(new SelectedKeywordDecoration()), 123 selected_keyword_decoration_(new SelectedKeywordDecoration()),
121 ev_bubble_decoration_( 124 ev_bubble_decoration_(
122 new EVBubbleDecoration(location_icon_decoration_.get())), 125 new EVBubbleDecoration(location_icon_decoration_.get())),
123 star_decoration_(new StarDecoration(command_updater)), 126 star_decoration_(new StarDecoration(command_updater)),
127 translate_decoration_(new TranslateDecoration(command_updater)),
124 zoom_decoration_(new ZoomDecoration(this)), 128 zoom_decoration_(new ZoomDecoration(this)),
125 keyword_hint_decoration_(new KeywordHintDecoration()), 129 keyword_hint_decoration_(new KeywordHintDecoration()),
126 mic_search_decoration_(new MicSearchDecoration(command_updater)), 130 mic_search_decoration_(new MicSearchDecoration(command_updater)),
127 generated_credit_card_decoration_( 131 generated_credit_card_decoration_(
128 new GeneratedCreditCardDecoration(this)), 132 new GeneratedCreditCardDecoration(this)),
129 search_button_decoration_(new SearchButtonDecoration(this)), 133 search_button_decoration_(new SearchButtonDecoration(this)),
130 browser_(browser), 134 browser_(browser),
131 weak_ptr_factory_(this) { 135 weak_ptr_factory_(this) {
132 136
133 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 137 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 bool LocationBarViewMac::IsEditable() { 321 bool LocationBarViewMac::IsEditable() {
318 return [field_ isEditable] ? true : false; 322 return [field_ isEditable] ? true : false;
319 } 323 }
320 324
321 void LocationBarViewMac::SetStarred(bool starred) { 325 void LocationBarViewMac::SetStarred(bool starred) {
322 star_decoration_->SetStarred(starred); 326 star_decoration_->SetStarred(starred);
323 UpdateStarDecorationVisibility(); 327 UpdateStarDecorationVisibility();
324 OnDecorationsChanged(); 328 OnDecorationsChanged();
325 } 329 }
326 330
331 void LocationBarViewMac::SetTranslateIconLit(bool on) {
332 translate_decoration_->SetLit(on);
333 OnDecorationsChanged();
334 }
335
327 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { 336 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) {
328 UpdateZoomDecoration(); 337 UpdateZoomDecoration();
329 OnDecorationsChanged(); 338 OnDecorationsChanged();
330 339
331 if (can_show_bubble && zoom_decoration_->IsVisible()) 340 if (can_show_bubble && zoom_decoration_->IsVisible())
332 zoom_decoration_->ShowBubble(YES); 341 zoom_decoration_->ShowBubble(YES);
333 } 342 }
334 343
335 bool LocationBarViewMac::IsStarEnabled() const { 344 bool LocationBarViewMac::IsStarEnabled() const {
336 return browser_defaults::bookmarks_enabled && 345 return browser_defaults::bookmarks_enabled &&
337 [field_ isEditable] && 346 [field_ isEditable] &&
338 !GetToolbarModel()->input_in_progress() && 347 !GetToolbarModel()->input_in_progress() &&
339 edit_bookmarks_enabled_.GetValue() && 348 edit_bookmarks_enabled_.GetValue() &&
340 !IsBookmarkStarHiddenByExtension(); 349 !IsBookmarkStarHiddenByExtension();
341 } 350 }
342 351
343 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { 352 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const {
344 DCHECK(IsStarEnabled()); 353 DCHECK(IsStarEnabled());
345 354
346 AutocompleteTextFieldCell* cell = [field_ cell]; 355 AutocompleteTextFieldCell* cell = [field_ cell];
347 const NSRect frame = [cell frameForDecoration:star_decoration_.get() 356 const NSRect frame = [cell frameForDecoration:star_decoration_.get()
348 inFrame:[field_ bounds]]; 357 inFrame:[field_ bounds]];
349 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); 358 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame);
350 return [field_ convertPoint:point toView:nil]; 359 return [field_ convertPoint:point toView:nil];
351 } 360 }
352 361
362 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const {
363 AutocompleteTextFieldCell* cell = [field_ cell];
364 const NSRect frame = [cell frameForDecoration:translate_decoration_.get()
365 inFrame:[field_ bounds]];
366 const NSPoint point = translate_decoration_->GetBubblePointInFrame(frame);
367 return [field_ convertPoint:point toView:nil];
368 }
369
353 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { 370 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const {
354 AutocompleteTextFieldCell* cell = [field_ cell]; 371 AutocompleteTextFieldCell* cell = [field_ cell];
355 if (ev_bubble_decoration_->IsVisible()) { 372 if (ev_bubble_decoration_->IsVisible()) {
356 const NSRect frame = [cell frameForDecoration:ev_bubble_decoration_.get() 373 const NSRect frame = [cell frameForDecoration:ev_bubble_decoration_.get()
357 inFrame:[field_ bounds]]; 374 inFrame:[field_ bounds]];
358 const NSPoint point = ev_bubble_decoration_->GetBubblePointInFrame(frame); 375 const NSPoint point = ev_bubble_decoration_->GetBubblePointInFrame(frame);
359 return [field_ convertPoint:point toView:nil]; 376 return [field_ convertPoint:point toView:nil];
360 } else { 377 } else {
361 const NSRect frame = 378 const NSRect frame =
362 [cell frameForDecoration:location_icon_decoration_.get() 379 [cell frameForDecoration:location_icon_decoration_.get()
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // right-hand decorations, which are not a static set. 413 // right-hand decorations, which are not a static set.
397 [cell clearDecorations]; 414 [cell clearDecorations];
398 if (origin_chip_decoration_.get()) 415 if (origin_chip_decoration_.get())
399 [cell addLeftDecoration:origin_chip_decoration_.get()]; 416 [cell addLeftDecoration:origin_chip_decoration_.get()];
400 [cell addLeftDecoration:location_icon_decoration_.get()]; 417 [cell addLeftDecoration:location_icon_decoration_.get()];
401 [cell addLeftDecoration:selected_keyword_decoration_.get()]; 418 [cell addLeftDecoration:selected_keyword_decoration_.get()];
402 if (!origin_chip_decoration_.get()) 419 if (!origin_chip_decoration_.get())
403 [cell addLeftDecoration:ev_bubble_decoration_.get()]; 420 [cell addLeftDecoration:ev_bubble_decoration_.get()];
404 [cell addRightDecoration:search_button_decoration_.get()]; 421 [cell addRightDecoration:search_button_decoration_.get()];
405 [cell addRightDecoration:star_decoration_.get()]; 422 [cell addRightDecoration:star_decoration_.get()];
423 [cell addRightDecoration:translate_decoration_.get()];
406 [cell addRightDecoration:zoom_decoration_.get()]; 424 [cell addRightDecoration:zoom_decoration_.get()];
407 [cell addRightDecoration:generated_credit_card_decoration_.get()]; 425 [cell addRightDecoration:generated_credit_card_decoration_.get()];
408 426
409 // Note that display order is right to left. 427 // Note that display order is right to left.
410 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 428 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
411 [cell addRightDecoration:page_action_decorations_[i]]; 429 [cell addRightDecoration:page_action_decorations_[i]];
412 } 430 }
413 431
414 for (ScopedVector<ContentSettingDecoration>::iterator i = 432 for (ScopedVector<ContentSettingDecoration>::iterator i =
415 content_setting_decorations_.begin(); 433 content_setting_decorations_.begin();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 NOTREACHED(); 531 NOTREACHED();
514 return NSZeroPoint; 532 return NSZeroPoint;
515 } 533 }
516 534
517 NSPoint bubble_point = decoration->GetBubblePointInFrame(frame); 535 NSPoint bubble_point = decoration->GetBubblePointInFrame(frame);
518 return [field_ convertPoint:bubble_point toView:nil]; 536 return [field_ convertPoint:bubble_point toView:nil];
519 } 537 }
520 538
521 void LocationBarViewMac::Update(const WebContents* contents) { 539 void LocationBarViewMac::Update(const WebContents* contents) {
522 UpdateStarDecorationVisibility(); 540 UpdateStarDecorationVisibility();
541 UpdateTranslateDecoration();
523 UpdateZoomDecoration(); 542 UpdateZoomDecoration();
524 RefreshPageActionDecorations(); 543 RefreshPageActionDecorations();
525 RefreshContentSettingsDecorations(); 544 RefreshContentSettingsDecorations();
526 UpdateMicSearchDecorationVisibility(); 545 UpdateMicSearchDecorationVisibility();
527 UpdateGeneratedCreditCardView(); 546 UpdateGeneratedCreditCardView();
528 if (contents) 547 if (contents)
529 omnibox_view_->OnTabChanged(contents); 548 omnibox_view_->OnTabChanged(contents);
530 else 549 else
531 omnibox_view_->Update(); 550 omnibox_view_->Update();
532 OnChanged(); 551 OnChanged();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 // BaseBubbleController will move it back to the correct position. 765 // BaseBubbleController will move it back to the correct position.
747 const NSPoint kOffset = NSMakePoint( 766 const NSPoint kOffset = NSMakePoint(
748 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth/2.0, 767 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth/2.0,
749 kFirstRunBubbleYOffset); 768 kFirstRunBubbleYOffset);
750 [FirstRunBubbleController showForView:field_ 769 [FirstRunBubbleController showForView:field_
751 offset:kOffset 770 offset:kOffset
752 browser:browser_ 771 browser:browser_
753 profile:profile()]; 772 profile:profile()];
754 } 773 }
755 774
775 void LocationBarViewMac::UpdateTranslateDecoration() {
776 WebContents* web_contents = GetWebContents();
777 if (!web_contents)
778 return;
779 LanguageState& language_state =
780 TranslateTabHelper::FromWebContents(web_contents)->GetLanguageState();
781 bool enabled = language_state.translate_enabled();
782 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
783 translate_decoration_->SetVisible(enabled);
784 translate_decoration_->SetLit(language_state.IsPageTranslated());
785 }
786
756 void LocationBarViewMac::UpdateZoomDecoration() { 787 void LocationBarViewMac::UpdateZoomDecoration() {
757 WebContents* web_contents = GetWebContents(); 788 WebContents* web_contents = GetWebContents();
758 if (!web_contents) 789 if (!web_contents)
759 return; 790 return;
760 791
761 zoom_decoration_->Update(ZoomController::FromWebContents(web_contents)); 792 zoom_decoration_->Update(ZoomController::FromWebContents(web_contents));
762 } 793 }
763 794
764 void LocationBarViewMac::UpdateStarDecorationVisibility() { 795 void LocationBarViewMac::UpdateStarDecorationVisibility() {
765 star_decoration_->SetVisible(IsStarEnabled()); 796 star_decoration_->SetVisible(IsStarEnabled());
766 } 797 }
767 798
768 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { 799 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() {
769 bool is_visible = !GetToolbarModel()->input_in_progress() && 800 bool is_visible = !GetToolbarModel()->input_in_progress() &&
770 browser_->search_model()->voice_search_supported(); 801 browser_->search_model()->voice_search_supported();
771 if (mic_search_decoration_->IsVisible() == is_visible) 802 if (mic_search_decoration_->IsVisible() == is_visible)
772 return false; 803 return false;
773 mic_search_decoration_->SetVisible(is_visible); 804 mic_search_decoration_->SetVisible(is_visible);
774 return true; 805 return true;
775 } 806 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698