| 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/l10n_util.h" | 11 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 13 #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" | 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 15 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 15 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "chrome/grit/theme_resources.h" | 17 #include "chrome/grit/theme_resources.h" |
| 18 #include "components/zoom/zoom_controller.h" | 18 #include "components/zoom/zoom_controller.h" |
| 19 #include "ui/base/cocoa/cocoa_base_utils.h" | 19 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 20 #include "ui/base/l10n/l10n_util_mac.h" | 20 #include "ui/base/l10n/l10n_util_mac.h" |
| 21 #include "ui/base/material_design/material_design_controller.h" | |
| 22 | 21 |
| 23 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) | 22 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| 24 : owner_(owner), | 23 : owner_(owner), |
| 25 bubble_(nil), | 24 bubble_(nil), |
| 26 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE) {} | 25 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE) {} |
| 27 | 26 |
| 28 ZoomDecoration::~ZoomDecoration() { | 27 ZoomDecoration::~ZoomDecoration() { |
| 29 [bubble_ closeWithoutAnimation]; | 28 [bubble_ closeWithoutAnimation]; |
| 30 bubble_.delegate = nil; | 29 bubble_.delegate = nil; |
| 31 } | 30 } |
| 32 | 31 |
| 33 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, | 32 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, |
| 34 bool default_zoom_changed, | 33 bool default_zoom_changed, |
| 35 bool location_bar_is_dark) { | 34 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 |
| 43 SetVisible(ShouldShowDecoration() && !zoom_controller->IsAtDefaultZoom()); |
| 44 |
| 44 base::string16 zoom_percent = | 45 base::string16 zoom_percent = |
| 45 base::FormatPercent(zoom_controller->GetZoomPercent()); | 46 base::FormatPercent(zoom_controller->GetZoomPercent()); |
| 46 // In Material Design there is no icon at the default zoom factor (100%), so | 47 // There is no icon at the default zoom factor (100%), so don't display a |
| 47 // don't display a tooltip either. | 48 // tooltip either. |
| 48 NSString* tooltip_string = | 49 NSString* tooltip_string = |
| 49 zoom_controller->IsAtDefaultZoom() | 50 zoom_controller->IsAtDefaultZoom() |
| 50 ? @"" | 51 ? @"" |
| 51 : l10n_util::GetNSStringF(IDS_TOOLTIP_ZOOM, zoom_percent); | 52 : l10n_util::GetNSStringF(IDS_TOOLTIP_ZOOM, zoom_percent); |
| 52 | 53 |
| 53 if (IsVisible() && [tooltip_ isEqualToString:tooltip_string] && | 54 if ([tooltip_ isEqualToString:tooltip_string] && !default_zoom_changed) |
| 54 !default_zoom_changed) { | |
| 55 return false; | 55 return false; |
| 56 } | |
| 57 | 56 |
| 58 ShowAndUpdateUI(zoom_controller, tooltip_string, location_bar_is_dark); | 57 UpdateUI(zoom_controller, tooltip_string, location_bar_is_dark); |
| 59 return true; | 58 return true; |
| 60 } | 59 } |
| 61 | 60 |
| 62 void ZoomDecoration::ShowBubble(BOOL auto_close) { | 61 void ZoomDecoration::ShowBubble(BOOL auto_close) { |
| 63 if (bubble_) { | 62 if (bubble_) { |
| 64 bubble_.delegate = nil; | 63 bubble_.delegate = nil; |
| 65 [[bubble_.window parentWindow] removeChildWindow:bubble_.window]; | 64 [[bubble_.window parentWindow] removeChildWindow:bubble_.window]; |
| 66 [bubble_.window orderOut:nil]; | 65 [bubble_.window orderOut:nil]; |
| 67 [bubble_ closeWithoutAnimation]; | 66 [bubble_ closeWithoutAnimation]; |
| 68 } | 67 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 88 | 87 |
| 89 void ZoomDecoration::CloseBubble() { | 88 void ZoomDecoration::CloseBubble() { |
| 90 [bubble_ close]; | 89 [bubble_ close]; |
| 91 } | 90 } |
| 92 | 91 |
| 93 void ZoomDecoration::HideUI() { | 92 void ZoomDecoration::HideUI() { |
| 94 [bubble_ close]; | 93 [bubble_ close]; |
| 95 SetVisible(false); | 94 SetVisible(false); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void ZoomDecoration::ShowAndUpdateUI(zoom::ZoomController* zoom_controller, | 97 void ZoomDecoration::UpdateUI(zoom::ZoomController* zoom_controller, |
| 99 NSString* tooltip_string, | 98 NSString* tooltip_string, |
| 100 bool location_bar_is_dark) { | 99 bool location_bar_is_dark) { |
| 101 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; | 100 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE; |
| 102 zoom::ZoomController::RelativeZoom relative_zoom = | 101 zoom::ZoomController::RelativeZoom relative_zoom = |
| 103 zoom_controller->GetZoomRelativeToDefault(); | 102 zoom_controller->GetZoomRelativeToDefault(); |
| 104 // In Material Design there is no icon at the default zoom factor. | 103 // There is no icon at the default zoom factor. |
| 105 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { | 104 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { |
| 106 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; | 105 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS; |
| 107 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { | 106 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { |
| 108 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; | 107 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS; |
| 109 } | 108 } |
| 110 | 109 |
| 111 SetImage(GetMaterialIcon(location_bar_is_dark)); | 110 SetImage(GetMaterialIcon(location_bar_is_dark)); |
| 112 | 111 |
| 113 tooltip_.reset([tooltip_string retain]); | 112 tooltip_.reset([tooltip_string retain]); |
| 114 | 113 |
| 115 SetVisible(true); | |
| 116 [bubble_ onZoomChanged]; | 114 [bubble_ onZoomChanged]; |
| 117 } | 115 } |
| 118 | 116 |
| 119 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { | 117 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
| 120 return NSMakePoint(cocoa_l10n_util::ShouldDoExperimentalRTLLayout() | 118 return NSMakePoint(cocoa_l10n_util::ShouldDoExperimentalRTLLayout() |
| 121 ? NSMinX(frame) | 119 ? NSMinX(frame) |
| 122 : NSMaxX(frame), | 120 : NSMaxX(frame), |
| 123 NSMaxY(frame)); | 121 NSMaxY(frame)); |
| 124 } | 122 } |
| 125 | 123 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // closed the decoration can be hidden. | 166 // closed the decoration can be hidden. |
| 169 if (IsAtDefaultZoom() && IsVisible()) { | 167 if (IsAtDefaultZoom() && IsVisible()) { |
| 170 SetVisible(false); | 168 SetVisible(false); |
| 171 owner_->OnDecorationsChanged(); | 169 owner_->OnDecorationsChanged(); |
| 172 } | 170 } |
| 173 } | 171 } |
| 174 | 172 |
| 175 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { | 173 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() const { |
| 176 return vector_icon_id_; | 174 return vector_icon_id_; |
| 177 } | 175 } |
| OLD | NEW |