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/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" | |
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" | |
19 | 24 |
20 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) | 25 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
21 : owner_(owner), | 26 : owner_(owner), |
22 bubble_(nil) { | 27 bubble_(nil) { |
23 } | 28 } |
24 | 29 |
25 ZoomDecoration::~ZoomDecoration() { | 30 ZoomDecoration::~ZoomDecoration() { |
26 [bubble_ closeWithoutAnimation]; | 31 [bubble_ closeWithoutAnimation]; |
27 bubble_.delegate = nil; | 32 bubble_.delegate = nil; |
28 } | 33 } |
29 | 34 |
30 bool ZoomDecoration::UpdateIfNecessary( | 35 bool ZoomDecoration::UpdateIfNecessary( |
31 ui_zoom::ZoomController* zoom_controller, bool default_zoom_changed) { | 36 ui_zoom::ZoomController* zoom_controller, |
37 bool default_zoom_changed, | |
38 bool location_bar_is_dark) { | |
32 if (!ShouldShowDecoration()) { | 39 if (!ShouldShowDecoration()) { |
33 if (!IsVisible() && !bubble_) | 40 if (!IsVisible() && !bubble_) |
34 return false; | 41 return false; |
35 | 42 |
36 HideUI(); | 43 HideUI(); |
37 return true; | 44 return true; |
38 } | 45 } |
39 | 46 |
40 base::string16 zoom_percent = | 47 base::string16 zoom_percent = |
41 base::IntToString16(zoom_controller->GetZoomPercent()); | 48 base::IntToString16(zoom_controller->GetZoomPercent()); |
42 NSString* zoom_string = | 49 NSString* zoom_string = |
43 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); | 50 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); |
44 | 51 |
45 if (IsVisible() && [tooltip_ isEqualToString:zoom_string] && | 52 if (IsVisible() && [tooltip_ isEqualToString:zoom_string] && |
46 !default_zoom_changed) { | 53 !default_zoom_changed) { |
47 return false; | 54 return false; |
48 } | 55 } |
49 | 56 |
50 ShowAndUpdateUI(zoom_controller, zoom_string); | 57 ShowAndUpdateUI(zoom_controller, zoom_string, location_bar_is_dark); |
51 return true; | 58 return true; |
52 } | 59 } |
53 | 60 |
54 void ZoomDecoration::ShowBubble(BOOL auto_close) { | 61 void ZoomDecoration::ShowBubble(BOOL auto_close) { |
55 if (bubble_) { | 62 if (bubble_) { |
56 bubble_.delegate = nil; | 63 bubble_.delegate = nil; |
57 [[bubble_.window parentWindow] removeChildWindow:bubble_.window]; | 64 [[bubble_.window parentWindow] removeChildWindow:bubble_.window]; |
58 [bubble_.window orderOut:nil]; | 65 [bubble_.window orderOut:nil]; |
59 [bubble_ closeWithoutAnimation]; | 66 [bubble_ closeWithoutAnimation]; |
60 } | 67 } |
(...skipping 20 matching lines...) Expand all Loading... | |
81 void ZoomDecoration::CloseBubble() { | 88 void ZoomDecoration::CloseBubble() { |
82 [bubble_ close]; | 89 [bubble_ close]; |
83 } | 90 } |
84 | 91 |
85 void ZoomDecoration::HideUI() { | 92 void ZoomDecoration::HideUI() { |
86 [bubble_ close]; | 93 [bubble_ close]; |
87 SetVisible(false); | 94 SetVisible(false); |
88 } | 95 } |
89 | 96 |
90 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller, | 97 void ZoomDecoration::ShowAndUpdateUI(ui_zoom::ZoomController* zoom_controller, |
91 NSString* tooltip_string) { | 98 NSString* tooltip_string, |
92 int image_id = IDR_ZOOM_NORMAL; | 99 bool location_bar_is_dark) { |
93 ui_zoom::ZoomController::RelativeZoom relative_zoom = | 100 if (ui::MaterialDesignController::IsModeMaterial()) { |
94 zoom_controller->GetZoomRelativeToDefault(); | 101 ui_zoom::ZoomController::RelativeZoom relative_zoom = |
95 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) | 102 zoom_controller->GetZoomRelativeToDefault(); |
96 image_id = IDR_ZOOM_MINUS; | 103 // There is no ZOOM_NORMAL under Material Design. |
97 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) | 104 gfx::VectorIconId iconId = |
98 image_id = IDR_ZOOM_PLUS; | 105 relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM |
106 ? gfx::VectorIconId::ZOOM_MINUS | |
107 : gfx::VectorIconId::ZOOM_PLUS; | |
99 | 108 |
100 SetImage(OmniboxViewMac::ImageForResource(image_id)); | 109 SkColor vectorIconColor = location_bar_is_dark ? SK_ColorWHITE |
110 : gfx::kChromeIconGrey; | |
111 NSImage *theImage = | |
Avi (use Gerrit)
2016/03/15 16:03:06
space after the *
shrike
2016/03/15 17:54:56
Done.
| |
112 NSImageFromImageSkia(gfx::CreateVectorIcon(iconId, | |
113 16, | |
114 vectorIconColor)); | |
115 SetImage(theImage); | |
116 } else { | |
117 int image_id = IDR_ZOOM_NORMAL; | |
118 ui_zoom::ZoomController::RelativeZoom relative_zoom = | |
119 zoom_controller->GetZoomRelativeToDefault(); | |
120 if (relative_zoom == ui_zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) | |
121 image_id = IDR_ZOOM_MINUS; | |
122 else if (relative_zoom == ui_zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) | |
123 image_id = IDR_ZOOM_PLUS; | |
124 | |
125 SetImage(OmniboxViewMac::ImageForResource(image_id)); | |
126 } | |
101 | 127 |
102 tooltip_.reset([tooltip_string retain]); | 128 tooltip_.reset([tooltip_string retain]); |
103 | 129 |
104 SetVisible(true); | 130 SetVisible(true); |
105 [bubble_ onZoomChanged]; | 131 [bubble_ onZoomChanged]; |
106 } | 132 } |
107 | 133 |
108 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { | 134 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
109 return NSMakePoint(NSMaxX(frame), NSMaxY(frame)); | 135 return NSMakePoint(NSMaxX(frame), NSMaxY(frame)); |
110 } | 136 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 bubble_ = nil; | 176 bubble_ = nil; |
151 | 177 |
152 // If the page is at default zoom then hiding the zoom decoration | 178 // If the page is at default zoom then hiding the zoom decoration |
153 // was suppressed while the bubble was open. Now that the bubble is | 179 // was suppressed while the bubble was open. Now that the bubble is |
154 // closed the decoration can be hidden. | 180 // closed the decoration can be hidden. |
155 if (IsAtDefaultZoom() && IsVisible()) { | 181 if (IsAtDefaultZoom() && IsVisible()) { |
156 SetVisible(false); | 182 SetVisible(false); |
157 owner_->OnDecorationsChanged(); | 183 owner_->OnDecorationsChanged(); |
158 } | 184 } |
159 } | 185 } |
OLD | NEW |