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/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.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/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
16 #include "components/ui/zoom/zoom_controller.h" | 16 #include "components/zoom/zoom_controller.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "ui/base/cocoa/cocoa_base_utils.h" | 18 #include "ui/base/cocoa/cocoa_base_utils.h" |
19 #include "ui/base/l10n/l10n_util_mac.h" | 19 #include "ui/base/l10n/l10n_util_mac.h" |
20 #include "ui/base/material_design/material_design_controller.h" | 20 #include "ui/base/material_design/material_design_controller.h" |
21 | 21 |
22 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) | 22 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
23 : owner_(owner), | 23 : owner_(owner), |
24 bubble_(nil), | 24 bubble_(nil), |
25 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE) {} | 25 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE) {} |
26 | 26 |
27 ZoomDecoration::~ZoomDecoration() { | 27 ZoomDecoration::~ZoomDecoration() { |
28 [bubble_ closeWithoutAnimation]; | 28 [bubble_ closeWithoutAnimation]; |
29 bubble_.delegate = nil; | 29 bubble_.delegate = nil; |
30 } | 30 } |
31 | 31 |
32 bool ZoomDecoration::UpdateIfNecessary( | 32 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, |
33 ui_zoom::ZoomController* zoom_controller, | 33 bool default_zoom_changed, |
34 bool default_zoom_changed, | 34 bool location_bar_is_dark) { |
35 bool location_bar_is_dark) { | |
36 if (!ShouldShowDecoration()) { | 35 if (!ShouldShowDecoration()) { |
37 if (!IsVisible() && !bubble_) | 36 if (!IsVisible() && !bubble_) |
38 return false; | 37 return false; |
39 | 38 |
40 HideUI(); | 39 HideUI(); |
41 return true; | 40 return true; |
42 } | 41 } |
43 | 42 |
44 base::string16 zoom_percent = | 43 base::string16 zoom_percent = |
45 base::FormatPercent(zoom_controller->GetZoomPercent()); | 44 base::FormatPercent(zoom_controller->GetZoomPercent()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 83 |
85 void ZoomDecoration::CloseBubble() { | 84 void ZoomDecoration::CloseBubble() { |
86 [bubble_ close]; | 85 [bubble_ close]; |
87 } | 86 } |
88 | 87 |
89 void ZoomDecoration::HideUI() { | 88 void ZoomDecoration::HideUI() { |
90 [bubble_ close]; | 89 [bubble_ close]; |
91 SetVisible(false); | 90 SetVisible(false); |
92 } | 91 } |
93 | 92 |
94 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller, | 93 void ZoomDecoration::ShowAndUpdateUI(zoom::ZoomController* zoom_controller, |
95 NSString* tooltip_string, | 94 NSString* tooltip_string, |
96 bool location_bar_is_dark) { | 95 bool location_bar_is_dark) { |
97 if (ui::MaterialDesignController::IsModeMaterial()) { | 96 if (ui::MaterialDesignController::IsModeMaterial()) { |
98 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; | 97 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; |
99 ui_zoom::ZoomController::RelativeZoom relative_zoom = | 98 zoom::ZoomController::RelativeZoom relative_zoom = |
100 zoom_controller->GetZoomRelativeToDefault(); | 99 zoom_controller->GetZoomRelativeToDefault(); |
101 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { | 100 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { |
102 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; | 101 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; |
103 } else if (relative_zoom == | 102 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { |
104 ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { | |
105 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; | 103 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; |
106 } | 104 } |
107 | 105 |
108 SetImage(GetMaterialIcon(location_bar_is_dark)); | 106 SetImage(GetMaterialIcon(location_bar_is_dark)); |
109 } else { | 107 } else { |
110 int image_id = IDR_ZOOM_NORMAL; | 108 int image_id = IDR_ZOOM_NORMAL; |
111 ui_zoom::ZoomController::RelativeZoom relative_zoom = | 109 zoom::ZoomController::RelativeZoom relative_zoom = |
112 zoom_controller->GetZoomRelativeToDefault(); | 110 zoom_controller->GetZoomRelativeToDefault(); |
113 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) | 111 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) |
114 image_id = IDR_ZOOM_MINUS; | 112 image_id = IDR_ZOOM_MINUS; |
115 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) | 113 else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) |
116 image_id = IDR_ZOOM_PLUS; | 114 image_id = IDR_ZOOM_PLUS; |
117 | 115 |
118 SetImage(OmniboxViewMac::ImageForResource(image_id)); | 116 SetImage(OmniboxViewMac::ImageForResource(image_id)); |
119 } | 117 } |
120 | 118 |
121 tooltip_.reset([tooltip_string retain]); | 119 tooltip_.reset([tooltip_string retain]); |
122 | 120 |
123 SetVisible(true); | 121 SetVisible(true); |
124 [bubble_ onZoomChanged]; | 122 [bubble_ onZoomChanged]; |
125 } | 123 } |
126 | 124 |
127 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { | 125 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
128 return NSMakePoint(NSMaxX(frame), NSMaxY(frame)); | 126 return NSMakePoint(NSMaxX(frame), NSMaxY(frame)); |
129 } | 127 } |
130 | 128 |
131 bool ZoomDecoration::IsAtDefaultZoom() const { | 129 bool ZoomDecoration::IsAtDefaultZoom() const { |
132 content::WebContents* web_contents = owner_->GetWebContents(); | 130 content::WebContents* web_contents = owner_->GetWebContents(); |
133 if (!web_contents) | 131 if (!web_contents) |
134 return false; | 132 return false; |
135 | 133 |
136 ui_zoom::ZoomController* zoomController = | 134 zoom::ZoomController* zoomController = |
137 ui_zoom::ZoomController::FromWebContents(web_contents); | 135 zoom::ZoomController::FromWebContents(web_contents); |
138 return zoomController && zoomController->IsAtDefaultZoom(); | 136 return zoomController && zoomController->IsAtDefaultZoom(); |
139 } | 137 } |
140 | 138 |
141 bool ZoomDecoration::ShouldShowDecoration() const { | 139 bool ZoomDecoration::ShouldShowDecoration() const { |
142 return owner_->GetWebContents() != NULL && | 140 return owner_->GetWebContents() != NULL && |
143 !owner_->GetToolbarModel()->input_in_progress() && | 141 !owner_->GetToolbarModel()->input_in_progress() && |
144 (bubble_ || !IsAtDefaultZoom()); | 142 (bubble_ || !IsAtDefaultZoom()); |
145 } | 143 } |
146 | 144 |
147 bool ZoomDecoration::AcceptsMousePress() { | 145 bool ZoomDecoration::AcceptsMousePress() { |
(...skipping 25 matching lines...) Expand all Loading... |
173 // closed the decoration can be hidden. | 171 // closed the decoration can be hidden. |
174 if (IsAtDefaultZoom() && IsVisible()) { | 172 if (IsAtDefaultZoom() && IsVisible()) { |
175 SetVisible(false); | 173 SetVisible(false); |
176 owner_->OnDecorationsChanged(); | 174 owner_->OnDecorationsChanged(); |
177 } | 175 } |
178 } | 176 } |
179 | 177 |
180 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { | 178 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { |
181 return vector_icon_id_; | 179 return vector_icon_id_; |
182 } | 180 } |
OLD | NEW |