| 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/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/ui/zoom/zoom_controller.h" | 15 #include "components/ui/zoom/zoom_controller.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
| 18 | 18 |
| 19 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) | 19 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| 20 : owner_(owner), | 20 : owner_(owner), |
| 21 bubble_(nil) { | 21 bubble_(nil) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 ZoomDecoration::~ZoomDecoration() { | 24 ZoomDecoration::~ZoomDecoration() { |
| 25 [bubble_ closeWithoutAnimation]; | 25 [bubble_ closeWithoutAnimation]; |
| 26 bubble_.delegate = nil; |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool ZoomDecoration::UpdateIfNecessary( | 29 bool ZoomDecoration::UpdateIfNecessary( |
| 29 ui_zoom::ZoomController* zoom_controller) { | 30 ui_zoom::ZoomController* zoom_controller) { |
| 30 if (!ShouldShowDecoration()) { | 31 if (!ShouldShowDecoration()) { |
| 31 if (!IsVisible() && !bubble_) | 32 if (!IsVisible() && !bubble_) |
| 32 return false; | 33 return false; |
| 33 | 34 |
| 34 HideUI(); | 35 HideUI(); |
| 35 return true; | 36 return true; |
| 36 } | 37 } |
| 37 | 38 |
| 38 base::string16 zoom_percent = | 39 base::string16 zoom_percent = |
| 39 base::IntToString16(zoom_controller->GetZoomPercent()); | 40 base::IntToString16(zoom_controller->GetZoomPercent()); |
| 40 NSString* zoom_string = | 41 NSString* zoom_string = |
| 41 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); | 42 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); |
| 42 | 43 |
| 43 if (IsVisible() && [tooltip_ isEqualToString:zoom_string]) | 44 if (IsVisible() && [tooltip_ isEqualToString:zoom_string]) |
| 44 return false; | 45 return false; |
| 45 | 46 |
| 46 ShowAndUpdateUI(zoom_controller, zoom_string); | 47 ShowAndUpdateUI(zoom_controller, zoom_string); |
| 47 return true; | 48 return true; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void ZoomDecoration::ShowBubble(BOOL auto_close) { | 51 void ZoomDecoration::ShowBubble(BOOL auto_close) { |
| 51 if (bubble_) | 52 if (bubble_) { |
| 52 return; | 53 bubble_.delegate = nil; |
| 54 [bubble_.window orderOut:nil]; |
| 55 [bubble_ closeWithoutAnimation]; |
| 56 } |
| 53 | 57 |
| 54 content::WebContents* web_contents = owner_->GetWebContents(); | 58 content::WebContents* web_contents = owner_->GetWebContents(); |
| 55 if (!web_contents) | 59 if (!web_contents) |
| 56 return; | 60 return; |
| 57 | 61 |
| 58 // Get the frame of the decoration. | 62 // Get the frame of the decoration. |
| 59 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); | 63 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
| 60 const NSRect frame = | 64 const NSRect frame = |
| 61 [[field cell] frameForDecoration:this inFrame:[field bounds]]; | 65 [[field cell] frameForDecoration:this inFrame:[field bounds]]; |
| 62 | 66 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 135 |
| 132 NSString* ZoomDecoration::GetToolTip() { | 136 NSString* ZoomDecoration::GetToolTip() { |
| 133 return tooltip_.get(); | 137 return tooltip_.get(); |
| 134 } | 138 } |
| 135 | 139 |
| 136 content::WebContents* ZoomDecoration::GetWebContents() { | 140 content::WebContents* ZoomDecoration::GetWebContents() { |
| 137 return owner_->GetWebContents(); | 141 return owner_->GetWebContents(); |
| 138 } | 142 } |
| 139 | 143 |
| 140 void ZoomDecoration::OnClose() { | 144 void ZoomDecoration::OnClose() { |
| 145 bubble_.delegate = nil; |
| 141 bubble_ = nil; | 146 bubble_ = nil; |
| 142 | 147 |
| 143 // If the page is at default zoom then hiding the zoom decoration | 148 // If the page is at default zoom then hiding the zoom decoration |
| 144 // was suppressed while the bubble was open. Now that the bubble is | 149 // was suppressed while the bubble was open. Now that the bubble is |
| 145 // closed the decoration can be hidden. | 150 // closed the decoration can be hidden. |
| 146 if (IsAtDefaultZoom() && IsVisible()) { | 151 if (IsAtDefaultZoom() && IsVisible()) { |
| 147 SetVisible(false); | 152 SetVisible(false); |
| 148 owner_->OnDecorationsChanged(); | 153 owner_->OnDecorationsChanged(); |
| 149 } | 154 } |
| 150 } | 155 } |
| OLD | NEW |