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

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

Issue 2834493007: MacViews: Allows the toolkit-views Zoom Dialog to be used (Closed)
Patch Set: MacViews: Allows the toolkit-views Zoom Dialog to be used (tests) Created 3 years, 8 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/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/app/vector_icons/vector_icons.h" 11 #include "chrome/app/vector_icons/vector_icons.h"
12 #include "chrome/browser/ui/browser_dialogs.h"
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #import "chrome/browser/ui/cocoa/l10n_util.h" 14 #import "chrome/browser/ui/cocoa/l10n_util.h"
13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 15 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
14 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 16 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 17 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
16 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 18 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
17 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
18 #include "chrome/grit/theme_resources.h" 20 #include "chrome/grit/theme_resources.h"
19 #include "components/zoom/zoom_controller.h" 21 #include "components/zoom/zoom_controller.h"
20 #include "ui/base/cocoa/cocoa_base_utils.h" 22 #include "ui/base/cocoa/cocoa_base_utils.h"
21 #include "ui/base/l10n/l10n_util_mac.h" 23 #include "ui/base/l10n/l10n_util_mac.h"
24 #include "ui/base/material_design/material_design_controller.h"
25 #import "ui/gfx/mac/coordinate_conversion.h"
22 26
23 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) 27 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
24 : owner_(owner), bubble_(nullptr), vector_icon_(nullptr) {} 28 : owner_(owner), bubble_(nullptr), vector_icon_(nullptr) {}
25 29
26 ZoomDecoration::~ZoomDecoration() { 30 ZoomDecoration::~ZoomDecoration() {
31 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
32 CloseBubble();
33 return;
34 }
27 [bubble_ closeWithoutAnimation]; 35 [bubble_ closeWithoutAnimation];
28 bubble_.delegate = nil; 36 bubble_.delegate = nil;
29 } 37 }
30 38
31 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, 39 bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller,
32 bool default_zoom_changed, 40 bool default_zoom_changed,
33 bool location_bar_is_dark) { 41 bool location_bar_is_dark) {
34 if (!ShouldShowDecoration()) { 42 if (!ShouldShowDecoration()) {
35 if (!IsVisible() && !bubble_) 43 if (!IsVisible() && !IsBubbleShown())
36 return false; 44 return false;
37 45
38 HideUI(); 46 HideUI();
39 return true; 47 return true;
40 } 48 }
41 49
42 BOOL old_visibility = IsVisible(); 50 BOOL old_visibility = IsVisible();
43 SetVisible(ShouldShowDecoration() && !zoom_controller->IsAtDefaultZoom()); 51 SetVisible(ShouldShowDecoration() && !zoom_controller->IsAtDefaultZoom());
44 52
45 base::string16 zoom_percent = 53 base::string16 zoom_percent =
(...skipping 24 matching lines...) Expand all
70 78
71 content::WebContents* web_contents = owner_->GetWebContents(); 79 content::WebContents* web_contents = owner_->GetWebContents();
72 if (!web_contents) 80 if (!web_contents)
73 return; 81 return;
74 82
75 // Get the frame of the decoration. 83 // Get the frame of the decoration.
76 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); 84 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
77 const NSRect frame = 85 const NSRect frame =
78 [[field cell] frameForDecoration:this inFrame:[field bounds]]; 86 [[field cell] frameForDecoration:this inFrame:[field bounds]];
79 87
88 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
89 NSWindow* window = [web_contents->GetNativeView() window];
90 if (!window) {
91 // The tab isn't active right now.
92 return;
93 }
94 BrowserWindowController* bwc =
msw 2017/04/24 18:53:38 nit: avoid acronym identifiers.
varkha 2017/04/26 04:52:59 Done.
95 [BrowserWindowController browserWindowControllerForWindow:window];
96 NSPoint anchor = [bwc bookmarkBubblePoint];
msw 2017/04/24 18:53:38 Why show this at the bookmark bubble point? Don't
varkha 2017/04/26 04:52:59 My guess is that this is called bookmark bubble po
97 gfx::Point anchor_point = gfx::ScreenPointFromNSPoint(
98 ui::ConvertPointFromWindowToScreen(window, anchor));
99 chrome::ShowZoomBubbleViewsAtPoint(web_contents, anchor_point,
100 auto_close == NO /* user_action */);
101 return;
102 }
103
80 // Find point for bubble's arrow in screen coordinates. 104 // Find point for bubble's arrow in screen coordinates.
81 NSPoint anchor = GetBubblePointInFrame(frame); 105 NSPoint anchor = GetBubblePointInFrame(frame);
82 anchor = [field convertPoint:anchor toView:nil]; 106 anchor = [field convertPoint:anchor toView:nil];
83 anchor = ui::ConvertPointFromWindowToScreen([field window], anchor); 107 anchor = ui::ConvertPointFromWindowToScreen([field window], anchor);
84 108
85 bubble_ = [[ZoomBubbleController alloc] initWithParentWindow:[field window] 109 bubble_ = [[ZoomBubbleController alloc] initWithParentWindow:[field window]
86 delegate:this]; 110 delegate:this];
87 [bubble_ showAnchoredAt:anchor autoClose:auto_close]; 111 [bubble_ showAnchoredAt:anchor autoClose:auto_close];
88 } 112 }
89 113
90 void ZoomDecoration::CloseBubble() { 114 void ZoomDecoration::CloseBubble() {
115 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
116 chrome::CloseZoomBubbleViews();
117 return;
118 }
91 [bubble_ close]; 119 [bubble_ close];
92 } 120 }
93 121
94 void ZoomDecoration::HideUI() { 122 void ZoomDecoration::HideUI() {
95 [bubble_ close]; 123 CloseBubble();
96 SetVisible(false); 124 SetVisible(false);
97 } 125 }
98 126
99 void ZoomDecoration::UpdateUI(zoom::ZoomController* zoom_controller, 127 void ZoomDecoration::UpdateUI(zoom::ZoomController* zoom_controller,
100 NSString* tooltip_string, 128 NSString* tooltip_string,
101 bool location_bar_is_dark) { 129 bool location_bar_is_dark) {
102 vector_icon_ = nullptr; 130 vector_icon_ = nullptr;
103 zoom::ZoomController::RelativeZoom relative_zoom = 131 zoom::ZoomController::RelativeZoom relative_zoom =
104 zoom_controller->GetZoomRelativeToDefault(); 132 zoom_controller->GetZoomRelativeToDefault();
105 // There is no icon at the default zoom factor. 133 // There is no icon at the default zoom factor.
106 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) { 134 if (relative_zoom == zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM) {
107 vector_icon_ = &kZoomMinusIcon; 135 vector_icon_ = &kZoomMinusIcon;
108 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) { 136 } else if (relative_zoom == zoom::ZoomController::ZOOM_ABOVE_DEFAULT_ZOOM) {
109 vector_icon_ = &kZoomPlusIcon; 137 vector_icon_ = &kZoomPlusIcon;
110 } 138 }
111 139
112 SetImage(GetMaterialIcon(location_bar_is_dark)); 140 SetImage(GetMaterialIcon(location_bar_is_dark));
113 141
114 tooltip_.reset([tooltip_string retain]); 142 tooltip_.reset([tooltip_string retain]);
115 143
116 [bubble_ onZoomChanged]; 144 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
145 chrome::RefreshZoomBubbleViews();
146 else
147 [bubble_ onZoomChanged];
117 } 148 }
118 149
119 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { 150 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) {
120 return NSMakePoint(cocoa_l10n_util::ShouldDoExperimentalRTLLayout() 151 return NSMakePoint(cocoa_l10n_util::ShouldDoExperimentalRTLLayout()
121 ? NSMinX(frame) 152 ? NSMinX(frame)
122 : NSMaxX(frame), 153 : NSMaxX(frame),
123 NSMaxY(frame)); 154 NSMaxY(frame));
124 } 155 }
125 156
126 bool ZoomDecoration::IsAtDefaultZoom() const { 157 bool ZoomDecoration::IsAtDefaultZoom() const {
127 content::WebContents* web_contents = owner_->GetWebContents(); 158 content::WebContents* web_contents = owner_->GetWebContents();
128 if (!web_contents) 159 if (!web_contents)
129 return false; 160 return false;
130 161
131 zoom::ZoomController* zoomController = 162 zoom::ZoomController* zoomController =
132 zoom::ZoomController::FromWebContents(web_contents); 163 zoom::ZoomController::FromWebContents(web_contents);
133 return zoomController && zoomController->IsAtDefaultZoom(); 164 return zoomController && zoomController->IsAtDefaultZoom();
134 } 165 }
135 166
167 bool ZoomDecoration::IsBubbleShown() const {
168 return (ui::MaterialDesignController::IsSecondaryUiMaterial() &&
169 chrome::IsZoomBubbleViewsShown()) ||
170 bubble_;
171 }
172
136 bool ZoomDecoration::ShouldShowDecoration() const { 173 bool ZoomDecoration::ShouldShowDecoration() const {
137 return owner_->GetWebContents() != NULL && 174 return owner_->GetWebContents() != NULL &&
138 !owner_->GetToolbarModel()->input_in_progress() && 175 !owner_->GetToolbarModel()->input_in_progress() &&
139 (bubble_ || !IsAtDefaultZoom()); 176 (IsBubbleShown() || !IsAtDefaultZoom());
140 } 177 }
141 178
142 bool ZoomDecoration::AcceptsMousePress() { 179 bool ZoomDecoration::AcceptsMousePress() {
143 return true; 180 return true;
144 } 181 }
145 182
146 bool ZoomDecoration::OnMousePressed(NSRect frame, NSPoint location) { 183 bool ZoomDecoration::OnMousePressed(NSRect frame, NSPoint location) {
147 if (bubble_) 184 if (IsBubbleShown()) {
148 CloseBubble(); 185 CloseBubble();
149 else 186 } else {
150 ShowBubble(YES); 187 BOOL auto_close = !ui::MaterialDesignController::IsSecondaryUiMaterial();
varkha 2017/04/24 12:59:37 Note: prefer this to inlining for being self-docum
msw 2017/04/24 18:53:38 Why would we change the auto-close behavior depend
varkha 2017/04/26 04:52:59 I don't think this should be any different from ot
188 ShowBubble(auto_close);
189 }
151 return true; 190 return true;
152 } 191 }
153 192
154 NSString* ZoomDecoration::GetToolTip() { 193 NSString* ZoomDecoration::GetToolTip() {
155 return tooltip_.get(); 194 return tooltip_.get();
156 } 195 }
157 196
158 content::WebContents* ZoomDecoration::GetWebContents() { 197 content::WebContents* ZoomDecoration::GetWebContents() {
159 return owner_->GetWebContents(); 198 return owner_->GetWebContents();
160 } 199 }
161 200
162 void ZoomDecoration::OnClose() { 201 void ZoomDecoration::OnClose() {
163 bubble_.delegate = nil; 202 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) {
164 bubble_ = nil; 203 bubble_.delegate = nil;
204 bubble_ = nil;
205 }
165 206
166 // If the page is at default zoom then hiding the zoom decoration 207 // If the page is at default zoom then hiding the zoom decoration
167 // was suppressed while the bubble was open. Now that the bubble is 208 // was suppressed while the bubble was open. Now that the bubble is
168 // closed the decoration can be hidden. 209 // closed the decoration can be hidden.
169 if (IsAtDefaultZoom() && IsVisible()) { 210 if (IsAtDefaultZoom() && IsVisible()) {
170 SetVisible(false); 211 SetVisible(false);
171 owner_->OnDecorationsChanged(); 212 owner_->OnDecorationsChanged();
172 } 213 }
173 } 214 }
174 215
175 const gfx::VectorIcon* ZoomDecoration::GetMaterialVectorIcon() const { 216 const gfx::VectorIcon* ZoomDecoration::GetMaterialVectorIcon() const {
176 return vector_icon_; 217 return vector_icon_;
177 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698