| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (!ShouldShowDecoration()) { | 35 if (!ShouldShowDecoration()) { |
| 36 if (!IsVisible() && !bubble_) | 36 if (!IsVisible() && !bubble_) |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 HideUI(); | 39 HideUI(); |
| 40 return true; | 40 return true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 base::string16 zoom_percent = | 43 base::string16 zoom_percent = |
| 44 base::FormatPercent(zoom_controller->GetZoomPercent()); | 44 base::FormatPercent(zoom_controller->GetZoomPercent()); |
| 45 NSString* zoom_string = | 45 // In Material Design there is no icon at the default zoom factor (100%), so |
| 46 l10n_util::GetNSStringF(IDS_TOOLTIP_ZOOM, zoom_percent); | 46 // don't display a tooltip either. |
| 47 NSString* tooltip_string = |
| 48 zoom_controller->IsAtDefaultZoom() |
| 49 ? @"" |
| 50 : l10n_util::GetNSStringF(IDS_TOOLTIP_ZOOM, zoom_percent); |
| 47 | 51 |
| 48 if (IsVisible() && [tooltip_ isEqualToString:zoom_string] && | 52 if (IsVisible() && [tooltip_ isEqualToString:tooltip_string] && |
| 49 !default_zoom_changed) { | 53 !default_zoom_changed) { |
| 50 return false; | 54 return false; |
| 51 } | 55 } |
| 52 | 56 |
| 53 ShowAndUpdateUI(zoom_controller, zoom_string, location_bar_is_dark); | 57 ShowAndUpdateUI(zoom_controller, tooltip_string, location_bar_is_dark); |
| 54 return true; | 58 return true; |
| 55 } | 59 } |
| 56 | 60 |
| 57 void ZoomDecoration::ShowBubble(BOOL auto_close) { | 61 void ZoomDecoration::ShowBubble(BOOL auto_close) { |
| 58 if (bubble_) { | 62 if (bubble_) { |
| 59 bubble_.delegate = nil; | 63 bubble_.delegate = nil; |
| 60 [[bubble_.window parentWindow] removeChildWindow:bubble_.window]; | 64 [[bubble_.window parentWindow] removeChildWindow:bubble_.window]; |
| 61 [bubble_.window orderOut:nil]; | 65 [bubble_.window orderOut:nil]; |
| 62 [bubble_ closeWithoutAnimation]; | 66 [bubble_ closeWithoutAnimation]; |
| 63 } | 67 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 89 [bubble_ close]; | 93 [bubble_ close]; |
| 90 SetVisible(false); | 94 SetVisible(false); |
| 91 } | 95 } |
| 92 | 96 |
| 93 void ZoomDecoration::ShowAndUpdateUI(zoom::ZoomController* zoom_controller, | 97 void ZoomDecoration::ShowAndUpdateUI(zoom::ZoomController* zoom_controller, |
| 94 NSString* tooltip_string, | 98 NSString* tooltip_string, |
| 95 bool location_bar_is_dark) { | 99 bool location_bar_is_dark) { |
| 96 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; | 100 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; |
| 97 zoom::ZoomController::RelativeZoom relative_zoom = | 101 zoom::ZoomController::RelativeZoom relative_zoom = |
| 98 zoom_controller->GetZoomRelativeToDefault(); | 102 zoom_controller->GetZoomRelativeToDefault(); |
| 103 // In Material Design there is no icon at the default zoom factor. |
| 99 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { | 104 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { |
| 100 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; | 105 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; |
| 101 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { | 106 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { |
| 102 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; | 107 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; |
| 103 } | 108 } |
| 104 | 109 |
| 105 SetImage(GetMaterialIcon(location_bar_is_dark)); | 110 SetImage(GetMaterialIcon(location_bar_is_dark)); |
| 106 | 111 |
| 107 tooltip_.reset([tooltip_string retain]); | 112 tooltip_.reset([tooltip_string retain]); |
| 108 | 113 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // closed the decoration can be hidden. | 164 // closed the decoration can be hidden. |
| 160 if (IsAtDefaultZoom() && IsVisible()) { | 165 if (IsAtDefaultZoom() && IsVisible()) { |
| 161 SetVisible(false); | 166 SetVisible(false); |
| 162 owner_->OnDecorationsChanged(); | 167 owner_->OnDecorationsChanged(); |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { | 171 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { |
| 167 return vector_icon_id_; | 172 return vector_icon_id_; |
| 168 } | 173 } |
| OLD | NEW |