| 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" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 void ZoomDecoration::HideUI() { | 92 void ZoomDecoration::HideUI() { |
| 93 [bubble_ close]; | 93 [bubble_ close]; |
| 94 SetVisible(false); | 94 SetVisible(false); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller, | 97 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller, |
| 98 NSString* tooltip_string, | 98 NSString* tooltip_string, |
| 99 bool location_bar_is_dark) { | 99 bool location_bar_is_dark) { |
| 100 if (ui::MaterialDesignController::IsModeMaterial()) { | 100 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 101 gfx::VectorIconId iconId = gfx::VectorIconId::VECTOR_ICON_NONE; |
| 101 ui_zoom::ZoomController::RelativeZoom relative_zoom = | 102 ui_zoom::ZoomController::RelativeZoom relative_zoom = |
| 102 zoom_controller->GetZoomRelativeToDefault(); | 103 zoom_controller->GetZoomRelativeToDefault(); |
| 103 // There is no ZOOM_NORMAL under Material Design. | 104 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { |
| 104 gfx::VectorIconId iconId = | 105 iconId = gfx::VectorIconId::ZOOM_MINUS; |
| 105 relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM | 106 } else if (relative_zoom == |
| 106 ? gfx::VectorIconId::ZOOM_MINUS | 107 ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { |
| 107 : gfx::VectorIconId::ZOOM_PLUS; | 108 iconId = gfx::VectorIconId::ZOOM_PLUS; |
| 109 } |
| 108 | 110 |
| 109 SkColor vectorIconColor = location_bar_is_dark ? SK_ColorWHITE | 111 NSImage* theImage = nil; |
| 110 : gfx::kChromeIconGrey; | 112 if (iconId != gfx::VectorIconId::VECTOR_ICON_NONE) { |
| 111 NSImage* theImage = | 113 SkColor vectorIconColor = location_bar_is_dark ? SK_ColorWHITE |
| 112 NSImageFromImageSkia(gfx::CreateVectorIcon(iconId, | 114 : gfx::kChromeIconGrey; |
| 113 16, | 115 theImage = NSImageFromImageSkia(gfx::CreateVectorIcon(iconId, |
| 114 vectorIconColor)); | 116 16, |
| 117 vectorIconColor)); |
| 118 } else { |
| 119 // Under Material Design there is no icon for ZOOM_NORMAL. This means |
| 120 // it should be OK to set a nil image. However if the user is actively |
| 121 // changing the zoom level and drives it back to 100%, there will be no |
| 122 // icon and the zoom bubble will still be visible. ShowBubble() asks the |
| 123 // autocomplete textfield for the zoom decoration's frame in order to |
| 124 // position the bubble, but when the decoration's image is nil it has |
| 125 // no frame. The result is the bubble positioned incorrectly. So, we have |
| 126 // to set an empty image. |
| 127 theImage = |
| 128 [[[NSImage alloc] initWithSize:NSMakeSize(16, 16)] autorelease]; |
| 129 } |
| 115 SetImage(theImage); | 130 SetImage(theImage); |
| 116 } else { | 131 } else { |
| 117 int image_id = IDR_ZOOM_NORMAL; | 132 int image_id = IDR_ZOOM_NORMAL; |
| 118 ui_zoom::ZoomController::RelativeZoom relative_zoom = | 133 ui_zoom::ZoomController::RelativeZoom relative_zoom = |
| 119 zoom_controller->GetZoomRelativeToDefault(); | 134 zoom_controller->GetZoomRelativeToDefault(); |
| 120 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) | 135 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) |
| 121 image_id = IDR_ZOOM_MINUS; | 136 image_id = IDR_ZOOM_MINUS; |
| 122 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) | 137 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) |
| 123 image_id = IDR_ZOOM_PLUS; | 138 image_id = IDR_ZOOM_PLUS; |
| 124 | 139 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 bubble_ = nil; | 191 bubble_ = nil; |
| 177 | 192 |
| 178 // If the page is at default zoom then hiding the zoom decoration | 193 // If the page is at default zoom then hiding the zoom decoration |
| 179 // was suppressed while the bubble was open. Now that the bubble is | 194 // was suppressed while the bubble was open. Now that the bubble is |
| 180 // closed the decoration can be hidden. | 195 // closed the decoration can be hidden. |
| 181 if (IsAtDefaultZoom() && IsVisible()) { | 196 if (IsAtDefaultZoom() && IsVisible()) { |
| 182 SetVisible(false); | 197 SetVisible(false); |
| 183 owner_->OnDecorationsChanged(); | 198 owner_->OnDecorationsChanged(); |
| 184 } | 199 } |
| 185 } | 200 } |
| OLD | NEW |