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

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

Issue 1680773006: Implement Material Design for Mac toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_master
Patch Set: Ready for review. Created 4 years, 9 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"
11 #include "base/mac/mac_logging.h" 11 #include "base/mac/mac_logging.h"
12 #include "chrome/browser/search/search.h" 12 #include "chrome/browser/search/search.h"
13 #include "chrome/browser/themes/theme_service.h"
13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 14 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" 15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
16 #import "chrome/browser/ui/cocoa/themed_window.h"
15 #import "extensions/common/feature_switch.h" 17 #import "extensions/common/feature_switch.h"
16 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
17 #import "third_party/mozilla/NSPasteboard+Utils.h" 19 #import "third_party/mozilla/NSPasteboard+Utils.h"
18 #import "ui/base/cocoa/appkit_utils.h" 20 #import "ui/base/cocoa/appkit_utils.h"
19 #import "ui/base/cocoa/nsview_additions.h" 21 #import "ui/base/cocoa/nsview_additions.h"
20 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h" 22 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h"
23 #include "ui/base/material_design/material_design_controller.h"
21 24
22 using extensions::FeatureSwitch; 25 using extensions::FeatureSwitch;
23 26
24 namespace { 27 namespace {
25 28
26 // Matches the clipping radius of |GradientButtonCell|. 29 // Matches the clipping radius of |GradientButtonCell|.
27 const CGFloat kCornerRadius = 3.0; 30 const CGFloat kCornerRadius = 3.0;
28 31
29 // 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
30 // bounds. 33 // bounds.
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 285 }
283 } 286 }
284 287
285 // I-beam cursor covers left-most to right-most. 288 // I-beam cursor covers left-most to right-most.
286 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame)); 289 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame));
287 } 290 }
288 291
289 - (void)drawWithFrame:(NSRect)frame inView:(NSView*)controlView { 292 - (void)drawWithFrame:(NSRect)frame inView:(NSView*)controlView {
290 // Background color. 293 // Background color.
291 const CGFloat lineWidth = [controlView cr_lineWidth]; 294 const CGFloat lineWidth = [controlView cr_lineWidth];
295 BOOL isModeMaterial = ui::MaterialDesignController::IsModeMaterial();
296 BOOL inDarkMode = [[controlView window] inIncognitoModeWithSystemTheme];
Avi (use Gerrit) 2016/03/01 19:59:06 hasDarkTheme? It's not clear when inIncognitoMode
shrike 2016/03/01 20:30:14 See previous reply.
297 BOOL showingFirstResponder = [self showsFirstResponder];
298 // Adjust the inset by 1/2 the line width to get a crisp line (screen pixels
299 // lay between cooridnate space lines).
300 CGFloat insetSize = 1 - lineWidth / 2.;
301 if (isModeMaterial && showingFirstResponder && !inDarkMode) {
302 insetSize++;
303 } else if (!isModeMaterial) {
304 insetSize = lineWidth == 0.5 ? 1.5 : 2.0;
305 }
306
307 // Compute the border's bezier path.
308 NSRect pathRect = NSInsetRect(frame, insetSize, insetSize);
309 NSBezierPath* path =
310 [NSBezierPath bezierPathWithRoundedRect:pathRect
311 xRadius:kCornerRadius
312 yRadius:kCornerRadius];
313 if (isModeMaterial) {
314 [path setLineWidth:showingFirstResponder ? lineWidth * 2 : lineWidth];
315 }
316
317 // Fill the background.
318 [[self backgroundColor] set];
292 if (isPopupMode_) { 319 if (isPopupMode_) {
293 [[self backgroundColor] set];
294 NSRectFillUsingOperation(NSInsetRect(frame, 1, 1), NSCompositeSourceOver); 320 NSRectFillUsingOperation(NSInsetRect(frame, 1, 1), NSCompositeSourceOver);
295 } else { 321 } else {
296 CGFloat insetSize = lineWidth == 0.5 ? 1.5 : 2.0; 322 [path fill];
297 NSRect fillRect = NSInsetRect(frame, insetSize, insetSize);
298 [[self backgroundColor] set];
299 [[NSBezierPath bezierPathWithRoundedRect:fillRect
300 xRadius:kCornerRadius
301 yRadius:kCornerRadius] fill];
302 } 323 }
303 324
304 // Border. 325 // Draw the border.
305 ui::DrawNinePartImage(frame, 326 if (isModeMaterial) {
306 isPopupMode_ ? kPopupBorderImageIds 327 [[NSColor colorWithCalibratedWhite:168 / 255. alpha:1] set];
307 : kNormalBorderImageIds, 328 [path stroke];
308 NSCompositeSourceOver, 329 } else {
309 1.0, 330 ui::DrawNinePartImage(frame,
310 true); 331 isPopupMode_ ? kPopupBorderImageIds
332 : kNormalBorderImageIds,
333 NSCompositeSourceOver,
334 1.0,
335 true);
336 }
311 337
312 // Interior contents. Drawn after the border as some of the interior controls 338 // Draw the interior contents. We do this after drawing the border as some
313 // draw over the border. 339 // of the interior controls draw over it.
314 [self drawInteriorWithFrame:frame inView:controlView]; 340 [self drawInteriorWithFrame:frame inView:controlView];
315 341
316 // Focus ring. 342 // Draw the focus ring.
317 if ([self showsFirstResponder]) { 343 if (showingFirstResponder) {
318 NSRect focusRingRect = NSInsetRect(frame, lineWidth, lineWidth); 344 if (!isModeMaterial) {
345 NSRect focusRingRect = NSInsetRect(frame, lineWidth, lineWidth);
346 path = [NSBezierPath bezierPathWithRoundedRect:focusRingRect
347 xRadius:kCornerRadius
348 yRadius:kCornerRadius];
349 [path setLineWidth:lineWidth * 2.0];
350 }
351
352 CGFloat alphaComponent = 0.5 / lineWidth;
353 if (isModeMaterial && inDarkMode) {
354 alphaComponent = 1;
355 }
319 [[[NSColor keyboardFocusIndicatorColor] 356 [[[NSColor keyboardFocusIndicatorColor]
320 colorWithAlphaComponent:0.5 / lineWidth] set]; 357 colorWithAlphaComponent:alphaComponent] set];
321 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:focusRingRect
322 xRadius:kCornerRadius
323 yRadius:kCornerRadius];
324 [path setLineWidth:lineWidth * 2.0];
325 [path stroke]; 358 [path stroke];
326 } 359 }
327 } 360 }
328 361
329 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 362 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
330 std::vector<LocationBarDecoration*> decorations; 363 std::vector<LocationBarDecoration*> decorations;
331 std::vector<NSRect> decorationFrames; 364 std::vector<NSRect> decorationFrames;
332 NSRect workingFrame; 365 NSRect workingFrame;
333 366
334 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 367 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_,
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 703
671 - (void)handleFocusEvent:(NSEvent*)event 704 - (void)handleFocusEvent:(NSEvent*)event
672 ofView:(AutocompleteTextField*)controlView { 705 ofView:(AutocompleteTextField*)controlView {
673 if ([controlView observer]) { 706 if ([controlView observer]) {
674 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; 707 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
675 [controlView observer]->OnSetFocus(controlDown); 708 [controlView observer]->OnSetFocus(controlDown);
676 } 709 }
677 } 710 }
678 711
679 @end 712 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698