Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm

Issue 1821823004: [Mac][Material Design] Update Omnibox dropdown on Mac to MD (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cocoa/cocoa_base_utils.h" 17 #include "ui/base/cocoa/cocoa_base_utils.h"
18 #include "ui/base/l10n/l10n_util_mac.h" 18 #include "ui/base/l10n/l10n_util_mac.h"
19 #include "ui/base/material_design/material_design_controller.h" 19 #include "ui/base/material_design/material_design_controller.h"
20 #include "ui/gfx/color_palette.h"
21 #include "ui/gfx/image/image_skia_util_mac.h"
22 #include "ui/gfx/paint_vector_icon.h"
23 #include "ui/gfx/vector_icons_public.h"
24 20
25 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) 21 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
26 : owner_(owner), 22 : owner_(owner),
27 bubble_(nil) { 23 bubble_(nil),
24 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE) {
28 } 25 }
29 26
30 ZoomDecoration::~ZoomDecoration() { 27 ZoomDecoration::~ZoomDecoration() {
31 [bubble_ closeWithoutAnimation]; 28 [bubble_ closeWithoutAnimation];
32 bubble_.delegate = nil; 29 bubble_.delegate = nil;
33 } 30 }
34 31
35 bool ZoomDecoration::UpdateIfNecessary( 32 bool ZoomDecoration::UpdateIfNecessary(
36 ui_zoom::ZoomController* zoom_controller, 33 ui_zoom::ZoomController* zoom_controller,
37 bool default_zoom_changed, 34 bool default_zoom_changed,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 88
92 void ZoomDecoration::HideUI() { 89 void ZoomDecoration::HideUI() {
93 [bubble_ close]; 90 [bubble_ close];
94 SetVisible(false); 91 SetVisible(false);
95 } 92 }
96 93
97 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller, 94 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller,
98 NSString* tooltip_string, 95 NSString* tooltip_string,
99 bool location_bar_is_dark) { 96 bool location_bar_is_dark) {
100 if (ui::MaterialDesignController::IsModeMaterial()) { 97 if (ui::MaterialDesignController::IsModeMaterial()) {
101 gfx::VectorIconId iconId = gfx::VectorIconId::VECTOR_ICON_NONE; 98 vector_icon_id_ = gfx::VectorIconId::VECTOR_ICON_NONE;
102 ui_zoom::ZoomController::RelativeZoom relative_zoom = 99 ui_zoom::ZoomController::RelativeZoom relative_zoom =
103 zoom_controller->GetZoomRelativeToDefault(); 100 zoom_controller->GetZoomRelativeToDefault();
104 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { 101 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) {
105 iconId = gfx::VectorIconId::ZOOM_MINUS; 102 vector_icon_id_ = gfx::VectorIconId::ZOOM_MINUS;
106 } else if (relative_zoom == 103 } else if (relative_zoom ==
107 ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { 104 ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) {
108 iconId = gfx::VectorIconId::ZOOM_PLUS; 105 vector_icon_id_ = gfx::VectorIconId::ZOOM_PLUS;
109 } 106 }
110 107
111 NSImage* theImage = nil; 108 SetImage(GetMaterialIcon(location_bar_is_dark));
112 if (iconId != gfx::VectorIconId::VECTOR_ICON_NONE) {
113 SkColor vectorIconColor = location_bar_is_dark ? SK_ColorWHITE
114 : gfx::kChromeIconGrey;
115 theImage = NSImageFromImageSkia(gfx::CreateVectorIcon(iconId,
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 }
130 SetImage(theImage);
131 } else { 109 } else {
132 int image_id = IDR_ZOOM_NORMAL; 110 int image_id = IDR_ZOOM_NORMAL;
133 ui_zoom::ZoomController::RelativeZoom relative_zoom = 111 ui_zoom::ZoomController::RelativeZoom relative_zoom =
134 zoom_controller->GetZoomRelativeToDefault(); 112 zoom_controller->GetZoomRelativeToDefault();
135 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) 113 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM)
136 image_id = IDR_ZOOM_MINUS; 114 image_id = IDR_ZOOM_MINUS;
137 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) 115 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM)
138 image_id = IDR_ZOOM_PLUS; 116 image_id = IDR_ZOOM_PLUS;
139 117
140 SetImage(OmniboxViewMac::ImageForResource(image_id)); 118 SetImage(OmniboxViewMac::ImageForResource(image_id));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 bubble_ = nil; 169 bubble_ = nil;
192 170
193 // If the page is at default zoom then hiding the zoom decoration 171 // If the page is at default zoom then hiding the zoom decoration
194 // was suppressed while the bubble was open. Now that the bubble is 172 // was suppressed while the bubble was open. Now that the bubble is
195 // closed the decoration can be hidden. 173 // closed the decoration can be hidden.
196 if (IsAtDefaultZoom() && IsVisible()) { 174 if (IsAtDefaultZoom() && IsVisible()) {
197 SetVisible(false); 175 SetVisible(false);
198 owner_->OnDecorationsChanged(); 176 owner_->OnDecorationsChanged();
199 } 177 }
200 } 178 }
179
180 gfx::VectorIconId ZoomDecoration::GetMaterialVectorIconId() {
181 return vector_icon_id_;
182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698