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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_strip_view.mm

Issue 867273003: Mac: Optimize toolbar/bookmark drawing during live resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/tabs/tab_strip_view.h" 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
6 6
7 #include <cmath> // floor 7 #include <cmath> // floor
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
(...skipping 27 matching lines...) Expand all
38 lastMouseUp_ = -1000.0; 38 lastMouseUp_ = -1000.0;
39 39
40 // Register to be an URL drop target. 40 // Register to be an URL drop target.
41 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); 41 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]);
42 42
43 [self setWantsLayer:YES]; 43 [self setWantsLayer:YES];
44 } 44 }
45 return self; 45 return self;
46 } 46 }
47 47
48 - (void)dealloc {
49 [[NSNotificationCenter defaultCenter] removeObserver:self];
50 [super dealloc];
51 }
52
53 - (void)viewWillMoveToWindow:(NSWindow*)window {
54 [super viewWillMoveToWindow:window];
55
56 if ([self window]) {
57 [[NSNotificationCenter defaultCenter]
58 removeObserver:self
59 name:NSWindowDidBecomeMainNotification
60 object:[self window]];
61 [[NSNotificationCenter defaultCenter]
62 removeObserver:self
63 name:NSWindowDidResignMainNotification
64 object:[self window]];
65 }
66 if (window) {
67 [[NSNotificationCenter defaultCenter]
68 addObserver:self
69 selector:@selector(windowFocusDidChange:)
70 name:NSWindowDidBecomeMainNotification
71 object:window];
72 [[NSNotificationCenter defaultCenter]
73 addObserver:self
74 selector:@selector(windowFocusDidChange:)
75 name:NSWindowDidResignMainNotification
76 object:window];
77 }
78 }
79
80 - (void)windowFocusDidChange:(NSNotification*)notification {
81 [self setNeedsDisplay:YES];
82 }
83
48 // Draw bottom border bitmap. Each tab is responsible for mimicking this bottom 84 // Draw bottom border bitmap. Each tab is responsible for mimicking this bottom
49 // border, unless it's the selected tab. 85 // border, unless it's the selected tab.
50 - (void)drawBorder:(NSRect)dirtyRect { 86 - (void)drawBorder:(NSRect)dirtyRect {
51 ThemeService* themeProvider = 87 ThemeService* themeProvider =
52 static_cast<ThemeService*>([[self window] themeProvider]); 88 static_cast<ThemeService*>([[self window] themeProvider]);
53 if (!themeProvider) 89 if (!themeProvider)
54 return; 90 return;
55 91
56 // First draw the toolbar bitmap, so that theme colors can shine through. 92 // First draw the toolbar bitmap, so that theme colors can shine through.
57 CGFloat backgroundHeight = 2 * [self cr_lineWidth]; 93 CGFloat backgroundHeight = 2 * [self cr_lineWidth];
58 if (NSMinY(dirtyRect) < backgroundHeight) { 94 if (NSMinY(dirtyRect) < backgroundHeight) {
59 gfx::ScopedNSGraphicsContextSaveGState scopedGState; 95 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
60 NSGraphicsContext *context = [NSGraphicsContext currentContext]; 96 NSGraphicsContext *context = [NSGraphicsContext currentContext];
61 NSPoint position = [[self window] themeImagePositionForAlignment: 97 NSPoint position = [[self window] themeImagePositionForAlignment:
62 THEME_IMAGE_ALIGN_WITH_TAB_STRIP]; 98 THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
63 [context cr_setPatternPhase:position forView:self]; 99 [context cr_setPatternPhase:position forView:self];
64 100
65 // Themes don't have an inactive image so only look for one if there's no 101 // Themes don't have an inactive image so only look for one if there's no
66 // theme. 102 // theme.
67 bool active = [[self window] isKeyWindow] || [[self window] isMainWindow] || 103 bool active = [[self window] isMainWindow] ||
Andre 2015/01/31 01:00:48 A utility window can be key without being main, bu
Robert Sesek 2015/02/02 19:32:16 What about with child windows?
Andre 2015/02/02 21:40:08 I tested that the browser window stays main when s
68 !themeProvider->UsingDefaultTheme(); 104 !themeProvider->UsingDefaultTheme();
69 int resource_id = active ? IDR_THEME_TOOLBAR : IDR_THEME_TOOLBAR_INACTIVE; 105 int resource_id = active ? IDR_THEME_TOOLBAR : IDR_THEME_TOOLBAR_INACTIVE;
70 [themeProvider->GetNSImageColorNamed(resource_id) set]; 106 [themeProvider->GetNSImageColorNamed(resource_id) set];
71 NSRectFill( 107 NSRectFill(
72 NSMakeRect(NSMinX(dirtyRect), 0, NSWidth(dirtyRect), backgroundHeight)); 108 NSMakeRect(NSMinX(dirtyRect), 0, NSWidth(dirtyRect), backgroundHeight));
73 } 109 }
74 110
75 // Draw the border bitmap, which is partially transparent. 111 // Draw the border bitmap, which is partially transparent.
76 NSImage* image = themeProvider->GetNSImageNamed(IDR_TOOLBAR_SHADE_TOP); 112 NSImage* image = themeProvider->GetNSImageNamed(IDR_TOOLBAR_SHADE_TOP);
77 if (NSMinY(dirtyRect) >= [image size].height) 113 if (NSMinY(dirtyRect) >= [image size].height)
78 return; 114 return;
79 115
80 NSRect borderRect = dirtyRect; 116 NSRect borderRect = dirtyRect;
81 borderRect.size.height = [image size].height; 117 borderRect.size.height = [image size].height;
82 borderRect.origin.y = 0; 118 borderRect.origin.y = 0;
83 119
84 BOOL focused = [[self window] isKeyWindow] || [[self window] isMainWindow]; 120 BOOL focused = [[self window] isMainWindow];
85 NSDrawThreePartImage(borderRect, nil, image, nil, /*vertical=*/ NO, 121 NSDrawThreePartImage(borderRect, nil, image, nil, /*vertical=*/ NO,
86 NSCompositeSourceOver, 122 NSCompositeSourceOver,
87 focused ? 1.0 : tabs::kImageNoFocusAlpha, 123 focused ? 1.0 : tabs::kImageNoFocusAlpha,
88 /*flipped=*/ NO); 124 /*flipped=*/ NO);
89 } 125 }
90 126
91 - (void)drawRect:(NSRect)rect { 127 - (void)drawRect:(NSRect)rect {
92 NSRect boundsRect = [self bounds]; 128 NSRect boundsRect = [self bounds];
93 129
94 [self drawBorder:boundsRect]; 130 [self drawBorder:boundsRect];
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 326
291 - (void)setNewTabButton:(NewTabButton*)button { 327 - (void)setNewTabButton:(NewTabButton*)button {
292 newTabButton_.reset([button retain]); 328 newTabButton_.reset([button retain]);
293 } 329 }
294 330
295 - (void)setController:(TabStripController*)controller { 331 - (void)setController:(TabStripController*)controller {
296 controller_ = controller; 332 controller_ = controller;
297 } 333 }
298 334
299 @end 335 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698