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

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

Issue 2375033002: cocoa browser: remove non-MD location bar support (Closed)
Patch Set: Created 4 years, 2 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/autocomplete_text_field_cell.h" 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 28
29 // Matches the clipping radius of |GradientButtonCell|. 29 // Matches the clipping radius of |GradientButtonCell|.
30 const CGFloat kCornerRadius = 3.0; 30 const CGFloat kCornerRadius = 3.0;
31 31
32 // How far to inset the left- and right-hand decorations from the field's 32 // How far to inset the left- and right-hand decorations from the field's
33 // bounds. 33 // bounds.
34 const CGFloat kRightDecorationXOffset = 5.0; 34 const CGFloat kRightDecorationXOffset = 5.0;
35 CGFloat LeftDecorationXOffset() { 35 CGFloat LeftDecorationXOffset() {
36 const CGFloat kLeftDecorationXOffset = 5.0; 36 const CGFloat kLeftDecorationXOffset = 6.0;
37 const CGFloat kLeftMaterialDecorationXOffset = 6.0; 37 return kLeftDecorationXOffset;
38 return ui::MaterialDesignController::IsModeMaterial()
39 ? kLeftMaterialDecorationXOffset
40 : kLeftDecorationXOffset;
41 } 38 }
Avi (use Gerrit) 2016/09/28 16:01:57 Put this back to being a "const CGFloat" like line
Elly Fong-Jones 2016/09/28 19:02:27 Done.
42 39
43 // The amount of padding on either side reserved for drawing 40 // The amount of padding on either side reserved for drawing
44 // decorations. [Views has |kItemPadding| == 3.] 41 // decorations. [Views has |kItemPadding| == 3.]
45 CGFloat DecorationsHorizontalPad() { 42 CGFloat DecorationsHorizontalPad() {
46 const CGFloat kDecorationHorizontalPad = 3.0; 43 const CGFloat kDecorationHorizontalPad = 4.0;
47 const CGFloat kMaterialDecorationHorizontalPad = 4.0; 44 return kDecorationHorizontalPad;
Avi (use Gerrit) 2016/09/28 16:01:58 ditto
Elly Fong-Jones 2016/09/28 19:02:27 Done.
48 return ui::MaterialDesignController::IsModeMaterial()
49 ? kMaterialDecorationHorizontalPad
50 : kDecorationHorizontalPad;
51 } 45 }
52 46
53 const ui::NinePartImageIds kPopupBorderImageIds =
54 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW);
55
56 const ui::NinePartImageIds kNormalBorderImageIds = IMAGE_GRID(IDR_TEXTFIELD);
57
58 // How long to wait for mouse-up on the location icon before assuming 47 // How long to wait for mouse-up on the location icon before assuming
59 // that the user wants to drag. 48 // that the user wants to drag.
60 const NSTimeInterval kLocationIconDragTimeout = 0.25; 49 const NSTimeInterval kLocationIconDragTimeout = 0.25;
61 50
62 // Calculate the positions for a set of decorations. |frame| is the 51 // Calculate the positions for a set of decorations. |frame| is the
63 // overall frame to do layout in, |remaining_frame| will get the 52 // overall frame to do layout in, |remaining_frame| will get the
64 // left-over space. |all_decorations| is the set of decorations to 53 // left-over space. |all_decorations| is the set of decorations to
65 // lay out, |decorations| will be set to the decorations which are 54 // lay out, |decorations| will be set to the decorations which are
66 // visible and which fit, in the same order as |all_decorations|, 55 // visible and which fit, in the same order as |all_decorations|,
67 // while |decoration_frames| will be the corresponding frames. 56 // while |decoration_frames| will be the corresponding frames.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 NSRect textFrame = [super textFrameForFrame:cellFrame]; 245 NSRect textFrame = [super textFrameForFrame:cellFrame];
257 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, 246 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_,
258 &decorations, &decorationFrames, &textFrame); 247 &decorations, &decorationFrames, &textFrame);
259 248
260 // The text needs to be slightly higher than its default position to match the 249 // The text needs to be slightly higher than its default position to match the
261 // Material Design spec. It turns out this adjustment is equal to the single 250 // Material Design spec. It turns out this adjustment is equal to the single
262 // pixel line width (so 1 on non-Retina, 0.5 on Retina). Make this adjustment 251 // pixel line width (so 1 on non-Retina, 0.5 on Retina). Make this adjustment
263 // after computing decoration positions because the decorations are already 252 // after computing decoration positions because the decorations are already
264 // correctly positioned. The spec also calls for positioning the text 1pt to 253 // correctly positioned. The spec also calls for positioning the text 1pt to
265 // the right of its default position. 254 // the right of its default position.
266 if (ui::MaterialDesignController::IsModeMaterial()) { 255 textFrame.origin.x += 1;
267 textFrame.origin.x += 1; 256 textFrame.size.width -= 1;
268 textFrame.size.width -= 1; 257 textFrame.origin.y -= singlePixelLineWidth_;
269 textFrame.origin.y -= singlePixelLineWidth_;
270 }
271 258
272 // NOTE: This function must closely match the logic in 259 // NOTE: This function must closely match the logic in
273 // |-drawInteriorWithFrame:inView:|. 260 // |-drawInteriorWithFrame:inView:|.
274 261
275 return textFrame; 262 return textFrame;
276 } 263 }
277 264
278 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { 265 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame {
279 std::vector<LocationBarDecoration*> decorations; 266 std::vector<LocationBarDecoration*> decorations;
280 std::vector<NSRect> decorationFrames; 267 std::vector<NSRect> decorationFrames;
(...skipping 29 matching lines...) Expand all
310 } else { 297 } else {
311 maxX = NSMaxX(decorationFrames[index]) + kDecorationHorizontalPad; 298 maxX = NSMaxX(decorationFrames[index]) + kDecorationHorizontalPad;
312 } 299 }
313 } 300 }
314 301
315 // I-beam cursor covers left-most to right-most. 302 // I-beam cursor covers left-most to right-most.
316 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame)); 303 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame));
317 } 304 }
318 305
319 - (void)drawWithFrame:(NSRect)frame inView:(NSView*)controlView { 306 - (void)drawWithFrame:(NSRect)frame inView:(NSView*)controlView {
320 BOOL isModeMaterial = ui::MaterialDesignController::IsModeMaterial();
321 BOOL inDarkMode = [[controlView window] inIncognitoModeWithSystemTheme]; 307 BOOL inDarkMode = [[controlView window] inIncognitoModeWithSystemTheme];
322 BOOL showingFirstResponder = [self showsFirstResponder]; 308 BOOL showingFirstResponder = [self showsFirstResponder];
323 // Adjust the inset by 1/2 the line width to get a crisp line (screen pixels 309 // Adjust the inset by 1/2 the line width to get a crisp line (screen pixels
324 // lay between cooridnate space lines). 310 // lay between cooridnate space lines).
325 CGFloat insetSize = 1 - singlePixelLineWidth_ / 2.; 311 CGFloat insetSize = 1 - singlePixelLineWidth_ / 2.;
326 if (isModeMaterial && showingFirstResponder && !inDarkMode) { 312 if (showingFirstResponder && !inDarkMode) {
327 insetSize++; 313 insetSize++;
328 } else if (!isModeMaterial) {
329 insetSize = singlePixelLineWidth_ == 0.5 ? 1.5 : 2.0;
330 } 314 }
331 315
332 // Compute the border's bezier path. 316 // Compute the border's bezier path.
333 NSRect pathRect = NSInsetRect(frame, insetSize, insetSize); 317 NSRect pathRect = NSInsetRect(frame, insetSize, insetSize);
334 NSBezierPath* path = 318 NSBezierPath* path =
335 [NSBezierPath bezierPathWithRoundedRect:pathRect 319 [NSBezierPath bezierPathWithRoundedRect:pathRect
336 xRadius:kCornerRadius 320 xRadius:kCornerRadius
337 yRadius:kCornerRadius]; 321 yRadius:kCornerRadius];
338 if (isModeMaterial) { 322 [path setLineWidth:showingFirstResponder ? singlePixelLineWidth_ * 2
339 [path setLineWidth:showingFirstResponder ? singlePixelLineWidth_ * 2 323 : singlePixelLineWidth_];
340 : singlePixelLineWidth_];
341 }
342 324
343 // Fill the background. 325 // Fill the background.
344 [[self backgroundColor] set]; 326 [[self backgroundColor] set];
345 if (isPopupMode_) { 327 if (isPopupMode_) {
346 NSRectFillUsingOperation(NSInsetRect(frame, 1, 1), NSCompositeSourceOver); 328 NSRectFillUsingOperation(NSInsetRect(frame, 1, 1), NSCompositeSourceOver);
347 } else { 329 } else {
348 [path fill]; 330 [path fill];
349 } 331 }
350 332
351 // Draw the border. 333 // Draw the border.
352 if (isModeMaterial) { 334 if (!inDarkMode) {
353 if (!inDarkMode) { 335 const CGFloat kNormalStrokeGray = 168 / 255.;
354 const CGFloat kNormalStrokeGray = 168 / 255.; 336 [[NSColor colorWithCalibratedWhite:kNormalStrokeGray alpha:1] set];
355 [[NSColor colorWithCalibratedWhite:kNormalStrokeGray alpha:1] set];
356 } else {
357 const CGFloat k30PercentAlpha = 0.3;
358 [[NSColor colorWithCalibratedWhite:0 alpha:k30PercentAlpha] set];
359 }
360 [path stroke];
361 } else { 337 } else {
362 ui::DrawNinePartImage(frame, 338 const CGFloat k30PercentAlpha = 0.3;
363 isPopupMode_ ? kPopupBorderImageIds 339 [[NSColor colorWithCalibratedWhite:0 alpha:k30PercentAlpha] set];
364 : kNormalBorderImageIds,
365 NSCompositeSourceOver,
366 1.0,
367 true);
368 } 340 }
341 [path stroke];
369 342
370 // Draw the interior contents. We do this after drawing the border as some 343 // Draw the interior contents. We do this after drawing the border as some
371 // of the interior controls draw over it. 344 // of the interior controls draw over it.
372 [self drawInteriorWithFrame:frame inView:controlView]; 345 [self drawInteriorWithFrame:frame inView:controlView];
373 346
374 // Draw the focus ring. 347 // Draw the focus ring.
375 if (showingFirstResponder) { 348 if (showingFirstResponder) {
376 if (!isModeMaterial) {
377 NSRect focusRingRect =
378 NSInsetRect(frame, singlePixelLineWidth_, singlePixelLineWidth_);
379 path = [NSBezierPath bezierPathWithRoundedRect:focusRingRect
380 xRadius:kCornerRadius
381 yRadius:kCornerRadius];
382 [path setLineWidth:singlePixelLineWidth_ * 2.0];
383 }
384
385 CGFloat alphaComponent = 0.5 / singlePixelLineWidth_; 349 CGFloat alphaComponent = 0.5 / singlePixelLineWidth_;
386 if (isModeMaterial && inDarkMode) { 350 if (inDarkMode) {
387 // Special focus color for Material Incognito. 351 // Special focus color for Material Incognito.
388 [[NSColor colorWithSRGBRed:123 / 255. 352 [[NSColor colorWithSRGBRed:123 / 255.
389 green:170 / 255. 353 green:170 / 255.
390 blue:247 / 255. 354 blue:247 / 255.
391 alpha:1] set]; 355 alpha:1] set];
392 } else { 356 } else {
393 [[[NSColor keyboardFocusIndicatorColor] 357 [[[NSColor keyboardFocusIndicatorColor]
394 colorWithAlphaComponent:alphaComponent] set]; 358 colorWithAlphaComponent:alphaComponent] set];
395 } 359 }
396 [path stroke]; 360 [path stroke];
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 740
777 - (void)handleFocusEvent:(NSEvent*)event 741 - (void)handleFocusEvent:(NSEvent*)event
778 ofView:(AutocompleteTextField*)controlView { 742 ofView:(AutocompleteTextField*)controlView {
779 if ([controlView observer]) { 743 if ([controlView observer]) {
780 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; 744 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
781 [controlView observer]->OnSetFocus(controlDown); 745 [controlView observer]->OnSetFocus(controlDown);
782 } 746 }
783 } 747 }
784 748
785 @end 749 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698