OLD | NEW |
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/strings/string16.h" | 7 #include "base/strings/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/location_bar/autocomplete_text_field.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
13 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 13 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "components/ui/zoom/zoom_controller.h" | 15 #include "components/ui/zoom/zoom_controller.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_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 } | 22 } |
23 | 23 |
24 ZoomDecoration::~ZoomDecoration() { | 24 ZoomDecoration::~ZoomDecoration() { |
25 [bubble_ closeWithoutAnimation]; | 25 [bubble_ closeWithoutAnimation]; |
| 26 bubble_.delegate = nil; |
26 } | 27 } |
27 | 28 |
28 bool ZoomDecoration::UpdateIfNecessary( | 29 bool ZoomDecoration::UpdateIfNecessary( |
29 ui_zoom::ZoomController* zoom_controller) { | 30 ui_zoom::ZoomController* zoom_controller) { |
30 if (!ShouldShowDecoration()) { | 31 if (!ShouldShowDecoration()) { |
31 if (!IsVisible() && !bubble_) | 32 if (!IsVisible() && !bubble_) |
32 return false; | 33 return false; |
33 | 34 |
34 HideUI(); | 35 HideUI(); |
35 return true; | 36 return true; |
36 } | 37 } |
37 | 38 |
38 base::string16 zoom_percent = | 39 base::string16 zoom_percent = |
39 base::IntToString16(zoom_controller->GetZoomPercent()); | 40 base::IntToString16(zoom_controller->GetZoomPercent()); |
40 NSString* zoom_string = | 41 NSString* zoom_string = |
41 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); | 42 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); |
42 | 43 |
43 if (IsVisible() && [tooltip_ isEqualToString:zoom_string]) | 44 if (IsVisible() && [tooltip_ isEqualToString:zoom_string]) |
44 return false; | 45 return false; |
45 | 46 |
46 ShowAndUpdateUI(zoom_controller, zoom_string); | 47 ShowAndUpdateUI(zoom_controller, zoom_string); |
47 return true; | 48 return true; |
48 } | 49 } |
49 | 50 |
50 void ZoomDecoration::ShowBubble(BOOL auto_close) { | 51 void ZoomDecoration::ShowBubble(BOOL auto_close) { |
51 if (bubble_) | 52 ZoomBubbleController* old_bubble = bubble_; |
52 return; | 53 old_bubble.delegate = nil; |
53 | 54 |
54 content::WebContents* web_contents = owner_->GetWebContents(); | 55 content::WebContents* web_contents = owner_->GetWebContents(); |
55 if (!web_contents) | 56 if (!web_contents) |
56 return; | 57 return; |
57 | 58 |
58 // Get the frame of the decoration. | 59 // Get the frame of the decoration. |
59 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); | 60 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
60 const NSRect frame = | 61 const NSRect frame = |
61 [[field cell] frameForDecoration:this inFrame:[field bounds]]; | 62 [[field cell] frameForDecoration:this inFrame:[field bounds]]; |
62 | 63 |
63 // Find point for bubble's arrow in screen coordinates. | 64 // Find point for bubble's arrow in screen coordinates. |
64 NSPoint anchor = GetBubblePointInFrame(frame); | 65 NSPoint anchor = GetBubblePointInFrame(frame); |
65 anchor = [field convertPoint:anchor toView:nil]; | 66 anchor = [field convertPoint:anchor toView:nil]; |
66 anchor = [[field window] convertBaseToScreen:anchor]; | 67 anchor = [[field window] convertBaseToScreen:anchor]; |
67 | 68 |
68 bubble_ = [[ZoomBubbleController alloc] initWithParentWindow:[field window] | 69 bubble_ = [[ZoomBubbleController alloc] initWithParentWindow:[field window] |
69 delegate:this]; | 70 delegate:this]; |
70 [bubble_ showAnchoredAt:anchor autoClose:auto_close]; | 71 [bubble_ showAnchoredAt:anchor autoClose:auto_close]; |
| 72 |
| 73 [old_bubble.window orderOut:nil]; |
| 74 [old_bubble closeWithoutAnimation]; |
71 } | 75 } |
72 | 76 |
73 void ZoomDecoration::CloseBubble() { | 77 void ZoomDecoration::CloseBubble() { |
74 [bubble_ close]; | 78 [bubble_ close]; |
75 } | 79 } |
76 | 80 |
77 void ZoomDecoration::HideUI() { | 81 void ZoomDecoration::HideUI() { |
78 [bubble_ close]; | 82 [bubble_ close]; |
79 SetVisible(false); | 83 SetVisible(false); |
80 } | 84 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 135 |
132 NSString* ZoomDecoration::GetToolTip() { | 136 NSString* ZoomDecoration::GetToolTip() { |
133 return tooltip_.get(); | 137 return tooltip_.get(); |
134 } | 138 } |
135 | 139 |
136 content::WebContents* ZoomDecoration::GetWebContents() { | 140 content::WebContents* ZoomDecoration::GetWebContents() { |
137 return owner_->GetWebContents(); | 141 return owner_->GetWebContents(); |
138 } | 142 } |
139 | 143 |
140 void ZoomDecoration::OnClose() { | 144 void ZoomDecoration::OnClose() { |
| 145 bubble_.delegate = nil; |
141 bubble_ = nil; | 146 bubble_ = nil; |
142 | 147 |
143 // If the page is at default zoom then hiding the zoom decoration | 148 // If the page is at default zoom then hiding the zoom decoration |
144 // was suppressed while the bubble was open. Now that the bubble is | 149 // was suppressed while the bubble was open. Now that the bubble is |
145 // closed the decoration can be hidden. | 150 // closed the decoration can be hidden. |
146 if (IsAtDefaultZoom() && IsVisible()) { | 151 if (IsAtDefaultZoom() && IsVisible()) { |
147 SetVisible(false); | 152 SetVisible(false); |
148 owner_->OnDecorationsChanged(); | 153 owner_->OnDecorationsChanged(); |
149 } | 154 } |
150 } | 155 } |
OLD | NEW |