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

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

Issue 10736028: Refactor browser window zoom handling and enable zoom icon on all platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | Annotate | Revision Log
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 #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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 26 matching lines...) Expand all
37 #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"
38 #import "chrome/browser/ui/cocoa/location_bar/chrome_to_mobile_decoration.h" 38 #import "chrome/browser/ui/cocoa/location_bar/chrome_to_mobile_decoration.h"
39 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" 39 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
40 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" 40 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h"
41 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" 41 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
42 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" 42 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
43 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" 43 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h"
44 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" 44 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h"
45 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" 45 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
47 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 48 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
50 #include "chrome/browser/ui/omnibox/location_bar_util.h" 51 #include "chrome/browser/ui/omnibox/location_bar_util.h"
51 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" 52 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h"
52 #include "chrome/browser/ui/tab_contents/tab_contents.h" 53 #include "chrome/browser/ui/tab_contents/tab_contents.h"
53 #include "chrome/common/chrome_notification_types.h" 54 #include "chrome/common/chrome_notification_types.h"
54 #include "chrome/common/extensions/extension.h" 55 #include "chrome/common/extensions/extension.h"
55 #include "chrome/common/extensions/extension_action.h" 56 #include "chrome/common/extensions/extension_action.h"
56 #include "chrome/common/extensions/extension_resource.h" 57 #include "chrome/common/extensions/extension_resource.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 disposition_(CURRENT_TAB), 93 disposition_(CURRENT_TAB),
93 location_icon_decoration_(new LocationIconDecoration(this)), 94 location_icon_decoration_(new LocationIconDecoration(this)),
94 selected_keyword_decoration_( 95 selected_keyword_decoration_(
95 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), 96 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())),
96 ev_bubble_decoration_( 97 ev_bubble_decoration_(
97 new EVBubbleDecoration(location_icon_decoration_.get(), 98 new EVBubbleDecoration(location_icon_decoration_.get(),
98 OmniboxViewMac::GetFieldFont())), 99 OmniboxViewMac::GetFieldFont())),
99 plus_decoration_(NULL), 100 plus_decoration_(NULL),
100 star_decoration_(new StarDecoration(command_updater)), 101 star_decoration_(new StarDecoration(command_updater)),
101 chrome_to_mobile_decoration_(NULL), 102 chrome_to_mobile_decoration_(NULL),
103 zoom_decoration_(new ZoomDecoration(toolbar_model)),
102 keyword_hint_decoration_( 104 keyword_hint_decoration_(
103 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), 105 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())),
104 profile_(profile), 106 profile_(profile),
105 browser_(browser), 107 browser_(browser),
106 toolbar_model_(toolbar_model), 108 toolbar_model_(toolbar_model),
107 transition_(content::PageTransitionFromInt( 109 transition_(content::PageTransitionFromInt(
108 content::PAGE_TRANSITION_TYPED | 110 content::PAGE_TRANSITION_TYPED |
109 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), 111 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)),
110 weak_ptr_factory_(this) { 112 weak_ptr_factory_(this) {
111 // Disable Chrome To Mobile for off-the-record and non-synced profiles, 113 // Disable Chrome To Mobile for off-the-record and non-synced profiles,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? 241 // TODO(shess): Why SaveStateToContents vs SaveStateToTab?
240 omnibox_view_->SaveStateToTab(contents); 242 omnibox_view_->SaveStateToTab(contents);
241 } 243 }
242 244
243 void LocationBarViewMac::Update(const WebContents* contents, 245 void LocationBarViewMac::Update(const WebContents* contents,
244 bool should_restore_state) { 246 bool should_restore_state) {
245 bool star_enabled = IsStarEnabled(); 247 bool star_enabled = IsStarEnabled();
246 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); 248 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
247 star_decoration_->SetVisible(star_enabled); 249 star_decoration_->SetVisible(star_enabled);
248 UpdateChromeToMobileEnabled(); 250 UpdateChromeToMobileEnabled();
251 UpdateZoomDecoration();
249 RefreshPageActionDecorations(); 252 RefreshPageActionDecorations();
250 RefreshContentSettingsDecorations(); 253 RefreshContentSettingsDecorations();
251 // OmniboxView restores state if the tab is non-NULL. 254 // OmniboxView restores state if the tab is non-NULL.
252 omnibox_view_->Update(should_restore_state ? contents : NULL); 255 omnibox_view_->Update(should_restore_state ? contents : NULL);
253 OnChanged(); 256 OnChanged();
254 } 257 }
255 258
256 void LocationBarViewMac::OnAutocompleteAccept( 259 void LocationBarViewMac::OnAutocompleteAccept(
257 const GURL& url, 260 const GURL& url,
258 WindowOpenDisposition disposition, 261 WindowOpenDisposition disposition,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 void LocationBarViewMac::TestPageActionPressed(size_t index) { 454 void LocationBarViewMac::TestPageActionPressed(size_t index) {
452 DCHECK_LT(index, page_action_decorations_.size()); 455 DCHECK_LT(index, page_action_decorations_.size());
453 if (index < page_action_decorations_.size()) 456 if (index < page_action_decorations_.size())
454 page_action_decorations_[index]->OnMousePressed(NSZeroRect); 457 page_action_decorations_[index]->OnMousePressed(NSZeroRect);
455 } 458 }
456 459
457 void LocationBarViewMac::SetEditable(bool editable) { 460 void LocationBarViewMac::SetEditable(bool editable) {
458 [field_ setEditable:editable ? YES : NO]; 461 [field_ setEditable:editable ? YES : NO];
459 star_decoration_->SetVisible(IsStarEnabled()); 462 star_decoration_->SetVisible(IsStarEnabled());
460 UpdateChromeToMobileEnabled(); 463 UpdateChromeToMobileEnabled();
464 UpdateZoomDecoration();
461 UpdatePageActions(); 465 UpdatePageActions();
462 Layout(); 466 Layout();
463 } 467 }
464 468
465 bool LocationBarViewMac::IsEditable() { 469 bool LocationBarViewMac::IsEditable() {
466 return [field_ isEditable] ? true : false; 470 return [field_ isEditable] ? true : false;
467 } 471 }
468 472
469 void LocationBarViewMac::SetStarred(bool starred) { 473 void LocationBarViewMac::OnImageDecorationsChanged() {
470 star_decoration_->SetStarred(starred);
471
472 // TODO(shess): The field-editor frame and cursor rects should not 474 // TODO(shess): The field-editor frame and cursor rects should not
473 // change, here. 475 // change, here.
474 [field_ updateCursorAndToolTipRects]; 476 [field_ updateCursorAndToolTipRects];
475 [field_ resetFieldEditorFrameIfNeeded]; 477 [field_ resetFieldEditorFrameIfNeeded];
476 [field_ setNeedsDisplay:YES]; 478 [field_ setNeedsDisplay:YES];
477 } 479 }
478 480
481 void LocationBarViewMac::SetStarred(bool starred) {
482 star_decoration_->SetStarred(starred);
483 OnImageDecorationsChanged();
484 }
485
479 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { 486 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) {
480 chrome_to_mobile_decoration_->SetLit(lit); 487 chrome_to_mobile_decoration_->SetLit(lit);
488 OnImageDecorationsChanged();
489 }
481 490
482 // TODO(shess): The field-editor frame and cursor rects should not 491 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) {
483 // change, here. 492 UpdateZoomDecoration();
484 [field_ updateCursorAndToolTipRects]; 493 OnImageDecorationsChanged();
485 [field_ resetFieldEditorFrameIfNeeded]; 494
486 [field_ setNeedsDisplay:YES]; 495 // TODO(dbeam): show a zoom bubble when appropriate.
487 } 496 }
488 497
489 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { 498 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const {
490 AutocompleteTextFieldCell* cell = [field_ cell]; 499 AutocompleteTextFieldCell* cell = [field_ cell];
491 const NSRect frame = [cell frameForDecoration:star_decoration_.get() 500 const NSRect frame = [cell frameForDecoration:star_decoration_.get()
492 inFrame:[field_ bounds]]; 501 inFrame:[field_ bounds]];
493 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); 502 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame);
494 return [field_ convertPoint:point toView:nil]; 503 return [field_ convertPoint:point toView:nil];
495 } 504 }
496 505
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // TODO(shess): Shortly, this code will live somewhere else, like in 651 // TODO(shess): Shortly, this code will live somewhere else, like in
643 // the constructor. I am still wrestling with how best to deal with 652 // the constructor. I am still wrestling with how best to deal with
644 // right-hand decorations, which are not a static set. 653 // right-hand decorations, which are not a static set.
645 [cell clearDecorations]; 654 [cell clearDecorations];
646 [cell addLeftDecoration:location_icon_decoration_.get()]; 655 [cell addLeftDecoration:location_icon_decoration_.get()];
647 [cell addLeftDecoration:selected_keyword_decoration_.get()]; 656 [cell addLeftDecoration:selected_keyword_decoration_.get()];
648 [cell addLeftDecoration:ev_bubble_decoration_.get()]; 657 [cell addLeftDecoration:ev_bubble_decoration_.get()];
649 if (plus_decoration_.get()) 658 if (plus_decoration_.get())
650 [cell addRightDecoration:plus_decoration_.get()]; 659 [cell addRightDecoration:plus_decoration_.get()];
651 [cell addRightDecoration:star_decoration_.get()]; 660 [cell addRightDecoration:star_decoration_.get()];
661 [cell addRightDecoration:zoom_decoration_.get()];
652 if (chrome_to_mobile_decoration_.get()) 662 if (chrome_to_mobile_decoration_.get())
653 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; 663 [cell addRightDecoration:chrome_to_mobile_decoration_.get()];
654 664
655 // Note that display order is right to left. 665 // Note that display order is right to left.
656 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 666 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
657 [cell addRightDecoration:page_action_decorations_[i]]; 667 [cell addRightDecoration:page_action_decorations_[i]];
658 } 668 }
659 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { 669 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) {
660 [cell addRightDecoration:content_setting_decorations_[i]]; 670 [cell addRightDecoration:content_setting_decorations_[i]];
661 } 671 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 void LocationBarViewMac::UpdateChromeToMobileEnabled() { 736 void LocationBarViewMac::UpdateChromeToMobileEnabled() {
727 if (!chrome_to_mobile_decoration_.get()) 737 if (!chrome_to_mobile_decoration_.get())
728 return; 738 return;
729 739
730 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); 740 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled());
731 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && 741 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() &&
732 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); 742 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles();
733 chrome_to_mobile_decoration_->SetVisible(enabled); 743 chrome_to_mobile_decoration_->SetVisible(enabled);
734 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); 744 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled);
735 } 745 }
746
747 void LocationBarViewMac::UpdateZoomDecoration() {
748 TabContents* tab_contents = GetTabContents();
749 if (!zoom_decoration_.get() || !tab_contents)
750 return;
751
752 zoom_decoration_->Update(tab_contents->zoom_controller());
753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698