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

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: address review comments 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 }
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 (IsAtDefaultZoom())
72 SetVisible(false);
Robert Sesek 2013/02/26 16:08:24 Is this necessary? Won't Update() be called when t
sail 2013/02/26 22:04:15 This is only for default zoom case. For example:
67 }; 73 };
68 bubble_ = 74 bubble_ =
69 [[ZoomBubbleController alloc] initWithParentWindow:[field window] 75 [[ZoomBubbleController alloc] initWithParentWindow:[field window]
70 closeObserver:observer]; 76 closeObserver:observer];
71 } 77 }
72 78
73 [bubble_ showForWebContents:web_contents 79 [bubble_ showForWebContents:web_contents
74 anchoredAt:anchor 80 anchoredAt:anchor
75 autoClose:auto_close]; 81 autoClose:auto_close];
76 } 82 }
77 83
78 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { 84 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) {
79 NSSize image_size = [GetImage() size]; 85 return NSMakePoint(NSMaxX(frame), NSMaxY(frame));
80 frame.origin.x += frame.size.width - image_size.width; 86 }
81 frame.size = image_size;
82 87
83 const NSRect draw_frame = GetDrawRectInFrame(frame); 88 bool ZoomDecoration::IsAtDefaultZoom() const {
84 return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame)); 89 content::WebContents* web_contents = owner_->GetWebContents();
90 if (!web_contents)
91 return false;
92 ZoomController* zoomController =
93 ZoomController::FromWebContents(web_contents);
94 return zoomController && zoomController->IsAtDefaultZoom();
95 }
96
97 bool ZoomDecoration::ShouldShowDecoration() const {
98 if (owner_->toolbar_model()->GetInputInProgress())
99 return false;
100 if (bubble_)
101 return true;
102 return !IsAtDefaultZoom();
85 } 103 }
86 104
87 bool ZoomDecoration::AcceptsMousePress() { 105 bool ZoomDecoration::AcceptsMousePress() {
88 return true; 106 return true;
89 } 107 }
90 108
91 bool ZoomDecoration::OnMousePressed(NSRect frame) { 109 bool ZoomDecoration::OnMousePressed(NSRect frame) {
92 ShowBubble(NO); 110 ShowBubble(NO);
93 return true; 111 return true;
94 } 112 }
95 113
96 NSString* ZoomDecoration::GetToolTip() { 114 NSString* ZoomDecoration::GetToolTip() {
97 return tooltip_.get(); 115 return tooltip_.get();
98 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698