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

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

Issue 12315069: Mac: Update zoom bubble UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 | 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/zoom_decoration.h" 5 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
6 6
7 #include "base/string16.h" 7 #include "base/string16.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" 10 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h"
11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
14 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 14 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
15 #include "chrome/browser/ui/zoom/zoom_controller.h" 15 #include "chrome/browser/ui/zoom/zoom_controller.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util_mac.h" 17 #include "ui/base/l10n/l10n_util_mac.h"
18 18
19 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) 19 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
20 : owner_(owner), 20 : owner_(owner),
21 bubble_(nil) { 21 bubble_(nil) {
22 Update(NULL);
23 } 22 }
24 23
25 ZoomDecoration::~ZoomDecoration() { 24 ZoomDecoration::~ZoomDecoration() {
26 } 25 }
27 26
28 void ZoomDecoration::Update(ZoomController* zoom_controller) { 27 void ZoomDecoration::Update(ZoomController* zoom_controller) {
29 if (!zoom_controller || zoom_controller->IsAtDefaultZoom()) { 28 if (!ShouldShowDecoration()) {
30 [bubble_ close]; 29 [bubble_ close];
31 SetVisible(false); 30 SetVisible(false);
32 return; 31 return;
33 } 32 }
34 33
35 SetImage(OmniboxViewMac::ImageForResource( 34 SetImage(OmniboxViewMac::ImageForResource(
36 zoom_controller->GetResourceForZoomLevel())); 35 zoom_controller->GetResourceForZoomLevel()));
37 36
38 string16 zoom_percent = base::IntToString16(zoom_controller->zoom_percent()); 37 string16 zoom_percent = base::IntToString16(zoom_controller->zoom_percent());
39 NSString* zoom_string = 38 NSString* zoom_string =
40 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); 39 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent);
41 tooltip_.reset([zoom_string retain]); 40 tooltip_.reset([zoom_string retain]);
42 41
43 SetVisible(true); 42 SetVisible(true);
44 43
45 [bubble_ onZoomChanged]; 44 [bubble_ onZoomChanged];
46 } 45 }
47 46
48 void ZoomDecoration::ShowBubble(BOOL auto_close) { 47 void ZoomDecoration::ShowBubble(BOOL auto_close) {
48 if (bubble_) {
49 [bubble_ close];
50 return;
51 }
Scott Hess - ex-Googler 2013/02/27 15:22:10 This maybe calls for a change to the method name,
sail 2013/02/27 18:48:18 Done. Changed to ToggleBubble()
52
49 content::WebContents* web_contents = owner_->GetWebContents(); 53 content::WebContents* web_contents = owner_->GetWebContents();
50 if (!web_contents) 54 if (!web_contents)
51 return; 55 return;
52 56
53 // Get the frame of the decoration. 57 // Get the frame of the decoration.
54 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); 58 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
55 AutocompleteTextFieldCell* cell = [field cell]; 59 AutocompleteTextFieldCell* cell = [field cell];
56 const NSRect frame = [cell frameForDecoration:this 60 const NSRect frame = [cell frameForDecoration:this
57 inFrame:[field bounds]]; 61 inFrame:[field bounds]];
58 62
59 // Find point for bubble's arrow in screen coordinates. 63 // Find point for bubble's arrow in screen coordinates.
60 NSPoint anchor = GetBubblePointInFrame(frame); 64 NSPoint anchor = GetBubblePointInFrame(frame);
61 anchor = [field convertPoint:anchor toView:nil]; 65 anchor = [field convertPoint:anchor toView:nil];
62 anchor = [[field window] convertBaseToScreen:anchor]; 66 anchor = [[field window] convertBaseToScreen:anchor];
63 67
64 if (!bubble_) { 68 if (!bubble_) {
65 void(^observer)(ZoomBubbleController*) = ^(ZoomBubbleController*) { 69 void(^observer)(ZoomBubbleController*) = ^(ZoomBubbleController*) {
66 bubble_ = nil; 70 bubble_ = nil;
71 // If the page is at default zoom then hiding the zoom decoration was
72 // suppressed while the bubble was open. Now that the bubble is closed
73 // the decoration can be hidden.
74 if (IsAtDefaultZoom())
75 SetVisible(false);
67 }; 76 };
68 bubble_ = 77 bubble_ =
69 [[ZoomBubbleController alloc] initWithParentWindow:[field window] 78 [[ZoomBubbleController alloc] initWithParentWindow:[field window]
70 closeObserver:observer]; 79 closeObserver:observer];
71 } 80 }
72 81
73 [bubble_ showForWebContents:web_contents 82 [bubble_ showForWebContents:web_contents
74 anchoredAt:anchor 83 anchoredAt:anchor
75 autoClose:auto_close]; 84 autoClose:auto_close];
76 } 85 }
77 86
78 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { 87 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) {
79 NSSize image_size = [GetImage() size]; 88 return NSMakePoint(NSMaxX(frame), NSMaxY(frame));
80 frame.origin.x += frame.size.width - image_size.width; 89 }
81 frame.size = image_size;
82 90
83 const NSRect draw_frame = GetDrawRectInFrame(frame); 91 bool ZoomDecoration::IsAtDefaultZoom() const {
84 return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame)); 92 content::WebContents* web_contents = owner_->GetWebContents();
93 if (!web_contents)
94 return false;
95 ZoomController* zoomController =
96 ZoomController::FromWebContents(web_contents);
97 return zoomController && zoomController->IsAtDefaultZoom();
98 }
99
100 bool ZoomDecoration::ShouldShowDecoration() const {
101 if (owner_->toolbar_model()->GetInputInProgress())
102 return false;
103 if (bubble_)
104 return true;
105 return !IsAtDefaultZoom();
85 } 106 }
86 107
87 bool ZoomDecoration::AcceptsMousePress() { 108 bool ZoomDecoration::AcceptsMousePress() {
88 return true; 109 return true;
89 } 110 }
90 111
91 bool ZoomDecoration::OnMousePressed(NSRect frame) { 112 bool ZoomDecoration::OnMousePressed(NSRect frame) {
92 ShowBubble(NO); 113 ShowBubble(NO);
93 return true; 114 return true;
94 } 115 }
95 116
96 NSString* ZoomDecoration::GetToolTip() { 117 NSString* ZoomDecoration::GetToolTip() {
97 return tooltip_.get(); 118 return tooltip_.get();
98 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698