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

Side by Side Diff: chrome/browser/ui/cocoa/dev_tools_controller.mm

Issue 388803003: [Mac] Replace SetOverlayView with AllowOtherViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, fixed comments Created 6 years, 5 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 | Annotate | Revision Log
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/dev_tools_controller.h" 5 #import "chrome/browser/ui/cocoa/dev_tools_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include <Cocoa/Cocoa.h> 10 #include <Cocoa/Cocoa.h>
(...skipping 12 matching lines...) Expand all
23 using content::WebContents; 23 using content::WebContents;
24 24
25 @interface DevToolsContainerView : BaseView { 25 @interface DevToolsContainerView : BaseView {
26 DevToolsContentsResizingStrategy strategy_; 26 DevToolsContentsResizingStrategy strategy_;
27 27
28 // Weak references. Ownership via -subviews. 28 // Weak references. Ownership via -subviews.
29 NSView* devToolsView_; 29 NSView* devToolsView_;
30 NSView* contentsView_; 30 NSView* contentsView_;
31 } 31 }
32 32
33 - (void)setContentsResizingStrategy: 33 - (void)setDevToolsView:(NSView*)devToolsView
34 (const DevToolsContentsResizingStrategy&)strategy; 34 withStrategy:(const DevToolsContentsResizingStrategy&)strategy;
35 - (void)adjustSubviews; 35 - (void)adjustSubviews;
36 - (void)showDevTools:(NSView*)devToolsView; 36 - (BOOL)hasDevToolsView;
37 - (void)hideDevTools;
38 37
39 @end 38 @end
40 39
41 40
42 @implementation DevToolsContainerView 41 @implementation DevToolsContainerView
43 42
44 - (void)setContentsResizingStrategy: 43 - (void)setDevToolsView:(NSView*)devToolsView
45 (const DevToolsContentsResizingStrategy&)strategy { 44 withStrategy:(const DevToolsContentsResizingStrategy&)strategy {
46 strategy_.CopyFrom(strategy); 45 strategy_.CopyFrom(strategy);
46
47 if (devToolsView == devToolsView_)
48 return;
49
50 if (devToolsView_) {
51 DCHECK_EQ(2u, [[self subviews] count]);
52 [devToolsView_ removeFromSuperview];
53 contentsView_ = nil;
54 devToolsView_ = nil;
55 }
56
57 if (devToolsView) {
58 NSArray* subviews = [self subviews];
59 DCHECK_EQ(1u, [subviews count]);
60 contentsView_ = [subviews objectAtIndex:0];
61 devToolsView_ = devToolsView;
62 // Place DevTools under contents.
63 [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil];
64 }
47 } 65 }
48 66
49 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { 67 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize {
50 [self adjustSubviews]; 68 [self adjustSubviews];
51 } 69 }
52 70
53 - (void)showDevTools:(NSView*)devToolsView { 71 - (BOOL)hasDevToolsView {
54 NSArray* subviews = [self subviews]; 72 return devToolsView_ != nil;
55 DCHECK_EQ(1u, [subviews count]);
56 contentsView_ = [subviews objectAtIndex:0];
57 devToolsView_ = devToolsView;
58 // Place DevTools under contents.
59 [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil];
60 }
61
62 - (void)hideDevTools {
63 DCHECK_EQ(2u, [[self subviews] count]);
64 [devToolsView_ removeFromSuperview];
65 contentsView_ = nil;
66 devToolsView_ = nil;
67 } 73 }
68 74
69 - (void)adjustSubviews { 75 - (void)adjustSubviews {
70 if (![[self subviews] count]) 76 if (![[self subviews] count])
71 return; 77 return;
72 78
73 if (!devToolsView_) { 79 if (!devToolsView_) {
74 DCHECK_EQ(1u, [[self subviews] count]); 80 DCHECK_EQ(1u, [[self subviews] count]);
75 NSView* contents = [[self subviews] objectAtIndex:0]; 81 NSView* contents = [[self subviews] objectAtIndex:0];
76 [contents setFrame:[self bounds]]; 82 [contents setFrame:[self bounds]];
77 return; 83 return;
78 } 84 }
79 85
80 DCHECK_EQ(2u, [[self subviews] count]); 86 DCHECK_EQ(2u, [[self subviews] count]);
81 87
82 gfx::Rect new_devtools_bounds; 88 gfx::Rect new_devtools_bounds;
83 gfx::Rect new_contents_bounds; 89 gfx::Rect new_contents_bounds;
84 ApplyDevToolsContentsResizingStrategy( 90 ApplyDevToolsContentsResizingStrategy(
85 strategy_, gfx::Size(NSSizeToCGSize([self bounds].size)), 91 strategy_, gfx::Size(NSSizeToCGSize([self bounds].size)),
86 [self flipNSRectToRect:[devToolsView_ bounds]], 92 [self flipNSRectToRect:[devToolsView_ bounds]],
87 [self flipNSRectToRect:[contentsView_ bounds]], 93 [self flipNSRectToRect:[contentsView_ bounds]],
88 &new_devtools_bounds, &new_contents_bounds); 94 &new_devtools_bounds, &new_contents_bounds);
89 [devToolsView_ setFrame:[self flipRectToNSRect:new_devtools_bounds]]; 95 [devToolsView_ setFrame:[self flipRectToNSRect:new_devtools_bounds]];
90 [contentsView_ setFrame:[self flipRectToNSRect:new_contents_bounds]]; 96 [contentsView_ setFrame:[self flipRectToNSRect:new_contents_bounds]];
91 } 97 }
92 98
93 @end 99 @end
94 100
95 @interface DevToolsController (Private)
96 - (void)showDevToolsView;
97 - (void)hideDevToolsView;
98 @end
99
100 101
101 @implementation DevToolsController 102 @implementation DevToolsController
102 103
103 - (id)init { 104 - (id)init {
104 if ((self = [super init])) { 105 if ((self = [super init])) {
105 devToolsContainerView_.reset( 106 devToolsContainerView_.reset(
106 [[DevToolsContainerView alloc] initWithFrame:NSZeroRect]); 107 [[DevToolsContainerView alloc] initWithFrame:NSZeroRect]);
107 [devToolsContainerView_ 108 [devToolsContainerView_
108 setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; 109 setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
109 } 110 }
110 return self; 111 return self;
111 } 112 }
112 113
113 - (NSView*)view { 114 - (NSView*)view {
114 return devToolsContainerView_.get(); 115 return devToolsContainerView_.get();
115 } 116 }
116 117
117 - (void)updateDevToolsForWebContents:(WebContents*)contents 118 - (void)updateDevToolsForWebContents:(WebContents*)contents
118 withProfile:(Profile*)profile { 119 withProfile:(Profile*)profile {
119 DevToolsContentsResizingStrategy strategy; 120 DevToolsContentsResizingStrategy strategy;
120 WebContents* devTools = DevToolsWindow::GetInTabWebContents( 121 WebContents* devTools = DevToolsWindow::GetInTabWebContents(
121 contents, &strategy); 122 contents, &strategy);
122 123
123 // Make sure we do not draw any transient arrangements of views. 124 // Make sure we do not draw any transient arrangements of views.
124 gfx::ScopedNSDisableScreenUpdates disabler; 125 gfx::ScopedNSDisableScreenUpdates disabler;
125 bool shouldHide = devTools_ && devTools_ != devTools;
126 bool shouldShow = devTools && devTools_ != devTools;
127 126
128 if (shouldHide) 127 if (devTools && ![devToolsContainerView_ hasDevToolsView]) {
129 [self hideDevToolsView]; 128 focusTracker_.reset(
130 129 [[FocusTracker alloc] initWithWindow:[devToolsContainerView_ window]]);
131 devTools_ = devTools;
132 if (devTools_) {
133 devTools_->SetOverlayView(
134 contents,
135 gfx::Point(strategy.insets().left(), strategy.insets().top()));
136 [devToolsContainerView_ setContentsResizingStrategy:strategy];
137 } else {
138 DevToolsContentsResizingStrategy zeroStrategy;
139 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy];
140 } 130 }
141 131
142 if (shouldShow) 132 if (!devTools && [devToolsContainerView_ hasDevToolsView]) {
143 [self showDevToolsView]; 133 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]];
134 focusTracker_.reset();
135 }
144 136
137 NSView* devToolsView = nil;
138 if (devTools) {
139 devToolsView = devTools->GetNativeView();
140 // |devToolsView| is a WebContentsViewCocoa object, whose ViewID was
141 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to
142 // VIEW_ID_DEV_TOOLS_DOCKED here.
143 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED);
144
145 devTools->SetAllowOtherViews(true);
146 contents->SetAllowOtherViews(true);
147 } else {
148 contents->SetAllowOtherViews(false);
149 }
150
151 [devToolsContainerView_ setDevToolsView:devToolsView withStrategy:strategy];
145 [devToolsContainerView_ adjustSubviews]; 152 [devToolsContainerView_ adjustSubviews];
146 } 153 }
147 154
148 - (void)showDevToolsView {
149 focusTracker_.reset(
150 [[FocusTracker alloc] initWithWindow:[devToolsContainerView_ window]]);
151
152 // |devToolsView| is a WebContentsViewCocoa object, whose ViewID was
153 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to
154 // VIEW_ID_DEV_TOOLS_DOCKED here.
155 NSView* devToolsView = devTools_->GetNativeView();
156 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED);
157
158 [devToolsContainerView_ showDevTools:devToolsView];
159 }
160
161 - (void)hideDevToolsView {
162 devTools_->RemoveOverlayView();
163 [devToolsContainerView_ hideDevTools];
164 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]];
165 focusTracker_.reset();
166 }
167
168 @end 155 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/dev_tools_controller.h ('k') | chrome/browser/ui/cocoa/dev_tools_controller_browsertest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698