| 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 #include "chrome/app/vector_icons/vector_icons.h" |
| 11 #import "chrome/browser/ui/cocoa/l10n_util.h" | 12 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 14 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 15 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 16 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 16 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 17 #include "chrome/grit/theme_resources.h" | 18 #include "chrome/grit/theme_resources.h" |
| 18 #include "components/zoom/zoom_controller.h" | 19 #include "components/zoom/zoom_controller.h" |
| 19 #include "ui/base/cocoa/cocoa_base_utils.h" | 20 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 20 #include "ui/base/l10n/l10n_util_mac.h" | 21 #include "ui/base/l10n/l10n_util_mac.h" |
| 21 | 22 |
| 22 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) | 23 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| 23 : owner_(owner), | 24 : owner_(owner), bubble_(nullptr), vector_icon_(nullptr) {} |
| 24 bubble_(nil), | |
| 25 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE) {} | |
| 26 | 25 |
| 27 ZoomDecoration::~ZoomDecoration() { | 26 ZoomDecoration::~ZoomDecoration() { |
| 28 [bubble_ closeWithoutAnimation]; | 27 [bubble_ closeWithoutAnimation]; |
| 29 bubble_.delegate = nil; | 28 bubble_.delegate = nil; |
| 30 } | 29 } |
| 31 | 30 |
| 32 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, | 31 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, |
| 33 bool default_zoom_changed, | 32 bool default_zoom_changed, |
| 34 bool location_bar_is_dark) { | 33 bool location_bar_is_dark) { |
| 35 if (!ShouldShowDecoration()) { | 34 if (!ShouldShowDecoration()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 89 } |
| 91 | 90 |
| 92 void ZoomDecoration::HideUI() { | 91 void ZoomDecoration::HideUI() { |
| 93 [bubble_ close]; | 92 [bubble_ close]; |
| 94 SetVisible(false); | 93 SetVisible(false); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void ZoomDecoration::UpdateUI(zoom::ZoomController* zoom_controller, | 96 void ZoomDecoration::UpdateUI(zoom::ZoomController* zoom_controller, |
| 98 NSString* tooltip_string, | 97 NSString* tooltip_string, |
| 99 bool location_bar_is_dark) { | 98 bool location_bar_is_dark) { |
| 100 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; | 99 vector_icon_ = nullptr; |
| 101 zoom::ZoomController::RelativeZoom relative_zoom = | 100 zoom::ZoomController::RelativeZoom relative_zoom = |
| 102 zoom_controller->GetZoomRelativeToDefault(); | 101 zoom_controller->GetZoomRelativeToDefault(); |
| 103 // There is no icon at the default zoom factor. | 102 // There is no icon at the default zoom factor. |
| 104 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { | 103 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { |
| 105 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; | 104 vector_icon_ = &kZoomMinusIcon; |
| 106 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { | 105 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { |
| 107 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; | 106 vector_icon_ = &kZoomPlusIcon; |
| 108 } | 107 } |
| 109 | 108 |
| 110 SetImage(GetMaterialIcon(location_bar_is_dark)); | 109 SetImage(GetMaterialIcon(location_bar_is_dark)); |
| 111 | 110 |
| 112 tooltip_.reset([tooltip_string retain]); | 111 tooltip_.reset([tooltip_string retain]); |
| 113 | 112 |
| 114 [bubble_ onZoomChanged]; | 113 [bubble_ onZoomChanged]; |
| 115 } | 114 } |
| 116 | 115 |
| 117 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { | 116 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 162 |
| 164 // If the page is at default zoom then hiding the zoom decoration | 163 // If the page is at default zoom then hiding the zoom decoration |
| 165 // was suppressed while the bubble was open. Now that the bubble is | 164 // was suppressed while the bubble was open. Now that the bubble is |
| 166 // closed the decoration can be hidden. | 165 // closed the decoration can be hidden. |
| 167 if (IsAtDefaultZoom() && IsVisible()) { | 166 if (IsAtDefaultZoom() && IsVisible()) { |
| 168 SetVisible(false); | 167 SetVisible(false); |
| 169 owner_->OnDecorationsChanged(); | 168 owner_->OnDecorationsChanged(); |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 | 171 |
| 173 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { | 172 const gfx::VectorIcon* ZoomDecoration::GetMaterialVectorIcon() const { |
| 174 return vector_icon_id_; | 173 return vector_icon_; |
| 175 } | 174 } |
| OLD | NEW |