| 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/browser/ui/zoom/zoom_controller.h" | |
| 15 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/ui/zoom/zoom_controller.h" |
| 16 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
| 17 | 18 |
| 18 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) | 19 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| 19 : owner_(owner), | 20 : owner_(owner), |
| 20 bubble_(nil) { | 21 bubble_(nil) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 ZoomDecoration::~ZoomDecoration() { | 24 ZoomDecoration::~ZoomDecoration() { |
| 24 [bubble_ closeWithoutAnimation]; | 25 [bubble_ closeWithoutAnimation]; |
| 25 } | 26 } |
| 26 | 27 |
| 27 bool ZoomDecoration::UpdateIfNecessary(ZoomController* zoom_controller) { | 28 bool ZoomDecoration::UpdateIfNecessary( |
| 29 components::ZoomController* zoom_controller) { |
| 28 if (!ShouldShowDecoration()) { | 30 if (!ShouldShowDecoration()) { |
| 29 if (!IsVisible() && !bubble_) | 31 if (!IsVisible() && !bubble_) |
| 30 return false; | 32 return false; |
| 31 | 33 |
| 32 HideUI(); | 34 HideUI(); |
| 33 return true; | 35 return true; |
| 34 } | 36 } |
| 35 | 37 |
| 36 base::string16 zoom_percent = | 38 base::string16 zoom_percent = |
| 37 base::IntToString16(zoom_controller->GetZoomPercent()); | 39 base::IntToString16(zoom_controller->GetZoomPercent()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 72 |
| 71 void ZoomDecoration::CloseBubble() { | 73 void ZoomDecoration::CloseBubble() { |
| 72 [bubble_ close]; | 74 [bubble_ close]; |
| 73 } | 75 } |
| 74 | 76 |
| 75 void ZoomDecoration::HideUI() { | 77 void ZoomDecoration::HideUI() { |
| 76 [bubble_ close]; | 78 [bubble_ close]; |
| 77 SetVisible(false); | 79 SetVisible(false); |
| 78 } | 80 } |
| 79 | 81 |
| 80 void ZoomDecoration::ShowAndUpdateUI(ZoomController* zoom_controller, | 82 void ZoomDecoration::ShowAndUpdateUI( |
| 81 NSString* tooltip_string) { | 83 components::ZoomController* zoom_controller, |
| 82 SetImage(OmniboxViewMac::ImageForResource( | 84 NSString* tooltip_string) { |
| 83 zoom_controller->GetResourceForZoomLevel())); | 85 int image_id = IDR_ZOOM_NORMAL; |
| 86 components::ZoomController::RelativeZoom relative_zoom = |
| 87 zoom_controller->GetZoomRelativeToDefault(); |
| 88 if (relative_zoom == components::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) |
| 89 image_id = IDR_ZOOM_MINUS; |
| 90 else if (relative_zoom == components::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) |
| 91 image_id = IDR_ZOOM_PLUS; |
| 92 |
| 93 SetImage(OmniboxViewMac::ImageForResource(image_id)); |
| 84 | 94 |
| 85 tooltip_.reset([tooltip_string retain]); | 95 tooltip_.reset([tooltip_string retain]); |
| 86 | 96 |
| 87 SetVisible(true); | 97 SetVisible(true); |
| 88 [bubble_ onZoomChanged]; | 98 [bubble_ onZoomChanged]; |
| 89 } | 99 } |
| 90 | 100 |
| 91 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { | 101 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
| 92 return NSMakePoint(NSMaxX(frame), NSMaxY(frame)); | 102 return NSMakePoint(NSMaxX(frame), NSMaxY(frame)); |
| 93 } | 103 } |
| 94 | 104 |
| 95 bool ZoomDecoration::IsAtDefaultZoom() const { | 105 bool ZoomDecoration::IsAtDefaultZoom() const { |
| 96 content::WebContents* web_contents = owner_->GetWebContents(); | 106 content::WebContents* web_contents = owner_->GetWebContents(); |
| 97 if (!web_contents) | 107 if (!web_contents) |
| 98 return false; | 108 return false; |
| 99 | 109 |
| 100 ZoomController* zoomController = | 110 components::ZoomController* zoomController = |
| 101 ZoomController::FromWebContents(web_contents); | 111 components::ZoomController::FromWebContents(web_contents); |
| 102 return zoomController && zoomController->IsAtDefaultZoom(); | 112 return zoomController && zoomController->IsAtDefaultZoom(); |
| 103 } | 113 } |
| 104 | 114 |
| 105 bool ZoomDecoration::ShouldShowDecoration() const { | 115 bool ZoomDecoration::ShouldShowDecoration() const { |
| 106 return owner_->GetWebContents() != NULL && | 116 return owner_->GetWebContents() != NULL && |
| 107 !owner_->GetToolbarModel()->input_in_progress() && | 117 !owner_->GetToolbarModel()->input_in_progress() && |
| 108 (bubble_ || !IsAtDefaultZoom()); | 118 (bubble_ || !IsAtDefaultZoom()); |
| 109 } | 119 } |
| 110 | 120 |
| 111 bool ZoomDecoration::AcceptsMousePress() { | 121 bool ZoomDecoration::AcceptsMousePress() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 132 bubble_ = nil; | 142 bubble_ = nil; |
| 133 | 143 |
| 134 // If the page is at default zoom then hiding the zoom decoration | 144 // If the page is at default zoom then hiding the zoom decoration |
| 135 // was suppressed while the bubble was open. Now that the bubble is | 145 // was suppressed while the bubble was open. Now that the bubble is |
| 136 // closed the decoration can be hidden. | 146 // closed the decoration can be hidden. |
| 137 if (IsAtDefaultZoom() && IsVisible()) { | 147 if (IsAtDefaultZoom() && IsVisible()) { |
| 138 SetVisible(false); | 148 SetVisible(false); |
| 139 owner_->OnDecorationsChanged(); | 149 owner_->OnDecorationsChanged(); |
| 140 } | 150 } |
| 141 } | 151 } |
| OLD | NEW |