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

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: . Created 6 years, 10 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/search/search.h" 26 #include "chrome/browser/search/search.h"
26 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
27 #include "chrome/browser/search_engines/template_url_service.h" 28 #include "chrome/browser/search_engines/template_url_service.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h" 29 #include "chrome/browser/search_engines/template_url_service_factory.h"
30 #include "chrome/browser/translate/translate_tab_helper.h"
29 #include "chrome/browser/ui/browser_instant_controller.h" 31 #include "chrome/browser/ui/browser_instant_controller.h"
30 #include "chrome/browser/ui/browser_list.h" 32 #include "chrome/browser/ui/browser_list.h"
31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " 33 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 34 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" 35 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h"
34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" 38 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
37 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" 39 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h"
38 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h " 40 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h "
39 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" 41 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
40 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" 42 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
41 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" 43 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h"
42 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" 44 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h"
43 #import "chrome/browser/ui/cocoa/location_bar/search_button_decoration.h" 45 #import "chrome/browser/ui/cocoa/location_bar/search_button_decoration.h"
44 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" 46 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
45 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 47 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
48 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h"
46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" 49 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 50 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 51 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 52 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
50 #include "chrome/browser/ui/omnibox/location_bar_util.h" 53 #include "chrome/browser/ui/omnibox/location_bar_util.h"
51 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" 54 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h"
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" 55 #include "chrome/browser/ui/tabs/tab_strip_model.h"
53 #include "chrome/browser/ui/toolbar/toolbar_model.h" 56 #include "chrome/browser/ui/toolbar/toolbar_model.h"
54 #include "chrome/browser/ui/zoom/zoom_controller.h" 57 #include "chrome/browser/ui/zoom/zoom_controller.h"
55 #include "chrome/common/chrome_switches.h" 58 #include "chrome/common/chrome_switches.h"
56 #include "chrome/common/pref_names.h" 59 #include "chrome/common/pref_names.h"
60 #include "components/translate/core/browser/language_state.h"
57 #include "content/public/browser/notification_service.h" 61 #include "content/public/browser/notification_service.h"
58 #include "content/public/browser/web_contents.h" 62 #include "content/public/browser/web_contents.h"
59 #include "extensions/common/extension.h" 63 #include "extensions/common/extension.h"
60 #include "extensions/common/permissions/permissions_data.h" 64 #include "extensions/common/permissions/permissions_data.h"
61 #include "grit/generated_resources.h" 65 #include "grit/generated_resources.h"
62 #include "grit/theme_resources.h" 66 #include "grit/theme_resources.h"
63 #include "net/base/net_util.h" 67 #include "net/base/net_util.h"
64 #include "skia/ext/skia_utils_mac.h" 68 #include "skia/ext/skia_utils_mac.h"
65 #import "ui/base/cocoa/cocoa_event_utils.h" 69 #import "ui/base/cocoa/cocoa_event_utils.h"
66 #include "ui/base/l10n/l10n_util_mac.h" 70 #include "ui/base/l10n/l10n_util_mac.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 Browser* browser) 113 Browser* browser)
110 : LocationBar(profile), 114 : LocationBar(profile),
111 OmniboxEditController(command_updater), 115 OmniboxEditController(command_updater),
112 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 116 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
113 field_(field), 117 field_(field),
114 location_icon_decoration_(new LocationIconDecoration(this)), 118 location_icon_decoration_(new LocationIconDecoration(this)),
115 selected_keyword_decoration_(new SelectedKeywordDecoration()), 119 selected_keyword_decoration_(new SelectedKeywordDecoration()),
116 ev_bubble_decoration_( 120 ev_bubble_decoration_(
117 new EVBubbleDecoration(location_icon_decoration_.get())), 121 new EVBubbleDecoration(location_icon_decoration_.get())),
118 star_decoration_(new StarDecoration(command_updater)), 122 star_decoration_(new StarDecoration(command_updater)),
123 translate_decoration_(new TranslateDecoration(command_updater)),
119 zoom_decoration_(new ZoomDecoration(this)), 124 zoom_decoration_(new ZoomDecoration(this)),
120 keyword_hint_decoration_(new KeywordHintDecoration()), 125 keyword_hint_decoration_(new KeywordHintDecoration()),
121 mic_search_decoration_(new MicSearchDecoration(command_updater)), 126 mic_search_decoration_(new MicSearchDecoration(command_updater)),
122 generated_credit_card_decoration_( 127 generated_credit_card_decoration_(
123 new GeneratedCreditCardDecoration(this)), 128 new GeneratedCreditCardDecoration(this)),
124 search_button_decoration_(new SearchButtonDecoration(this)), 129 search_button_decoration_(new SearchButtonDecoration(this)),
125 browser_(browser), 130 browser_(browser),
126 weak_ptr_factory_(this) { 131 weak_ptr_factory_(this) {
127 132
128 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 133 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 bool LocationBarViewMac::IsEditable() { 314 bool LocationBarViewMac::IsEditable() {
310 return [field_ isEditable] ? true : false; 315 return [field_ isEditable] ? true : false;
311 } 316 }
312 317
313 void LocationBarViewMac::SetStarred(bool starred) { 318 void LocationBarViewMac::SetStarred(bool starred) {
314 star_decoration_->SetStarred(starred); 319 star_decoration_->SetStarred(starred);
315 UpdateStarDecorationVisibility(); 320 UpdateStarDecorationVisibility();
316 OnDecorationsChanged(); 321 OnDecorationsChanged();
317 } 322 }
318 323
324 void LocationBarViewMac::SetTranslateIconToggled(bool on) {
325 translate_decoration_->SetToggled(on);
326 OnDecorationsChanged();
327 }
328
319 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { 329 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) {
320 UpdateZoomDecoration(); 330 UpdateZoomDecoration();
321 OnDecorationsChanged(); 331 OnDecorationsChanged();
322 332
323 if (can_show_bubble && zoom_decoration_->IsVisible()) 333 if (can_show_bubble && zoom_decoration_->IsVisible())
324 zoom_decoration_->ShowBubble(YES); 334 zoom_decoration_->ShowBubble(YES);
325 } 335 }
326 336
327 bool LocationBarViewMac::IsStarEnabled() const { 337 bool LocationBarViewMac::IsStarEnabled() const {
328 return browser_defaults::bookmarks_enabled && 338 return browser_defaults::bookmarks_enabled &&
329 [field_ isEditable] && 339 [field_ isEditable] &&
330 !GetToolbarModel()->input_in_progress() && 340 !GetToolbarModel()->input_in_progress() &&
331 edit_bookmarks_enabled_.GetValue() && 341 edit_bookmarks_enabled_.GetValue() &&
332 !IsBookmarkStarHiddenByExtension(); 342 !IsBookmarkStarHiddenByExtension();
333 } 343 }
334 344
335 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { 345 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const {
336 DCHECK(IsStarEnabled()); 346 DCHECK(IsStarEnabled());
337 347
338 AutocompleteTextFieldCell* cell = [field_ cell]; 348 AutocompleteTextFieldCell* cell = [field_ cell];
339 const NSRect frame = [cell frameForDecoration:star_decoration_.get() 349 const NSRect frame = [cell frameForDecoration:star_decoration_.get()
340 inFrame:[field_ bounds]]; 350 inFrame:[field_ bounds]];
341 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); 351 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame);
342 return [field_ convertPoint:point toView:nil]; 352 return [field_ convertPoint:point toView:nil];
343 } 353 }
344 354
355 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const {
356 AutocompleteTextFieldCell* cell = [field_ cell];
357 const NSRect frame = [cell frameForDecoration:translate_decoration_.get()
358 inFrame:[field_ bounds]];
359 const NSPoint point = translate_decoration_->GetBubblePointInFrame(frame);
360 return [field_ convertPoint:point toView:nil];
361 }
362
345 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { 363 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const {
346 AutocompleteTextFieldCell* cell = [field_ cell]; 364 AutocompleteTextFieldCell* cell = [field_ cell];
347 if (ev_bubble_decoration_->IsVisible()) { 365 if (ev_bubble_decoration_->IsVisible()) {
348 const NSRect frame = [cell frameForDecoration:ev_bubble_decoration_.get() 366 const NSRect frame = [cell frameForDecoration:ev_bubble_decoration_.get()
349 inFrame:[field_ bounds]]; 367 inFrame:[field_ bounds]];
350 const NSPoint point = ev_bubble_decoration_->GetBubblePointInFrame(frame); 368 const NSPoint point = ev_bubble_decoration_->GetBubblePointInFrame(frame);
351 return [field_ convertPoint:point toView:nil]; 369 return [field_ convertPoint:point toView:nil];
352 } else { 370 } else {
353 const NSRect frame = 371 const NSRect frame =
354 [cell frameForDecoration:location_icon_decoration_.get() 372 [cell frameForDecoration:location_icon_decoration_.get()
(...skipping 30 matching lines...) Expand all
385 // Reset the left-hand decorations. 403 // Reset the left-hand decorations.
386 // TODO(shess): Shortly, this code will live somewhere else, like in 404 // TODO(shess): Shortly, this code will live somewhere else, like in
387 // the constructor. I am still wrestling with how best to deal with 405 // the constructor. I am still wrestling with how best to deal with
388 // right-hand decorations, which are not a static set. 406 // right-hand decorations, which are not a static set.
389 [cell clearDecorations]; 407 [cell clearDecorations];
390 [cell addLeftDecoration:location_icon_decoration_.get()]; 408 [cell addLeftDecoration:location_icon_decoration_.get()];
391 [cell addLeftDecoration:selected_keyword_decoration_.get()]; 409 [cell addLeftDecoration:selected_keyword_decoration_.get()];
392 [cell addLeftDecoration:ev_bubble_decoration_.get()]; 410 [cell addLeftDecoration:ev_bubble_decoration_.get()];
393 [cell addRightDecoration:search_button_decoration_.get()]; 411 [cell addRightDecoration:search_button_decoration_.get()];
394 [cell addRightDecoration:star_decoration_.get()]; 412 [cell addRightDecoration:star_decoration_.get()];
413 [cell addRightDecoration:translate_decoration_.get()];
395 [cell addRightDecoration:zoom_decoration_.get()]; 414 [cell addRightDecoration:zoom_decoration_.get()];
396 [cell addRightDecoration:generated_credit_card_decoration_.get()]; 415 [cell addRightDecoration:generated_credit_card_decoration_.get()];
397 416
398 // Note that display order is right to left. 417 // Note that display order is right to left.
399 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 418 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
400 [cell addRightDecoration:page_action_decorations_[i]]; 419 [cell addRightDecoration:page_action_decorations_[i]];
401 } 420 }
402 421
403 for (ScopedVector<ContentSettingDecoration>::iterator i = 422 for (ScopedVector<ContentSettingDecoration>::iterator i =
404 content_setting_decorations_.begin(); 423 content_setting_decorations_.begin();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 NOTREACHED(); 521 NOTREACHED();
503 return NSZeroPoint; 522 return NSZeroPoint;
504 } 523 }
505 524
506 NSPoint bubble_point = decoration->GetBubblePointInFrame(frame); 525 NSPoint bubble_point = decoration->GetBubblePointInFrame(frame);
507 return [field_ convertPoint:bubble_point toView:nil]; 526 return [field_ convertPoint:bubble_point toView:nil];
508 } 527 }
509 528
510 void LocationBarViewMac::Update(const WebContents* contents) { 529 void LocationBarViewMac::Update(const WebContents* contents) {
511 UpdateStarDecorationVisibility(); 530 UpdateStarDecorationVisibility();
531 UpdateTranslateDecoration();
512 UpdateZoomDecoration(); 532 UpdateZoomDecoration();
513 RefreshPageActionDecorations(); 533 RefreshPageActionDecorations();
514 RefreshContentSettingsDecorations(); 534 RefreshContentSettingsDecorations();
515 UpdateMicSearchDecorationVisibility(); 535 UpdateMicSearchDecorationVisibility();
516 UpdateGeneratedCreditCardView(); 536 UpdateGeneratedCreditCardView();
517 if (contents) 537 if (contents)
518 omnibox_view_->OnTabChanged(contents); 538 omnibox_view_->OnTabChanged(contents);
519 else 539 else
520 omnibox_view_->Update(); 540 omnibox_view_->Update();
521 OnChanged(); 541 OnChanged();
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 // BaseBubbleController will move it back to the correct position. 740 // BaseBubbleController will move it back to the correct position.
721 const NSPoint kOffset = NSMakePoint( 741 const NSPoint kOffset = NSMakePoint(
722 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth/2.0, 742 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth/2.0,
723 kFirstRunBubbleYOffset); 743 kFirstRunBubbleYOffset);
724 [FirstRunBubbleController showForView:field_ 744 [FirstRunBubbleController showForView:field_
725 offset:kOffset 745 offset:kOffset
726 browser:browser_ 746 browser:browser_
727 profile:profile()]; 747 profile:profile()];
728 } 748 }
729 749
750 void LocationBarViewMac::UpdateTranslateDecoration() {
751 WebContents* web_contents = GetWebContents();
752 if (!web_contents)
753 return;
754 LanguageState& language_state = TranslateTabHelper::FromWebContents(
755 web_contents)->GetLanguageState();
756 bool enabled = language_state.translate_enabled();
757 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
758 translate_decoration_->SetVisible(enabled);
759 translate_decoration_->SetToggled(language_state.IsPageTranslated());
760 }
761
730 void LocationBarViewMac::UpdateZoomDecoration() { 762 void LocationBarViewMac::UpdateZoomDecoration() {
731 WebContents* web_contents = GetWebContents(); 763 WebContents* web_contents = GetWebContents();
732 if (!web_contents) 764 if (!web_contents)
733 return; 765 return;
734 766
735 zoom_decoration_->Update(ZoomController::FromWebContents(web_contents)); 767 zoom_decoration_->Update(ZoomController::FromWebContents(web_contents));
736 } 768 }
737 769
738 void LocationBarViewMac::UpdateStarDecorationVisibility() { 770 void LocationBarViewMac::UpdateStarDecorationVisibility() {
739 star_decoration_->SetVisible(IsStarEnabled()); 771 star_decoration_->SetVisible(IsStarEnabled());
740 } 772 }
741 773
742 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { 774 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() {
743 bool is_visible = !GetToolbarModel()->input_in_progress() && 775 bool is_visible = !GetToolbarModel()->input_in_progress() &&
744 browser_->search_model()->voice_search_supported(); 776 browser_->search_model()->voice_search_supported();
745 if (mic_search_decoration_->IsVisible() == is_visible) 777 if (mic_search_decoration_->IsVisible() == is_visible)
746 return false; 778 return false;
747 mic_search_decoration_->SetVisible(is_visible); 779 mic_search_decoration_->SetVisible(is_visible);
748 return true; 780 return true;
749 } 781 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698