OLD | NEW |
---|---|
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> |
11 | 11 |
12 #include "base/command_line.h" | |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
20 #include "content/public/common/content_switches.h" | |
19 #include "ui/base/cocoa/base_view.h" | 21 #include "ui/base/cocoa/base_view.h" |
20 #include "ui/base/cocoa/focus_tracker.h" | 22 #include "ui/base/cocoa/focus_tracker.h" |
23 #include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" | |
21 #include "ui/gfx/size_conversions.h" | 24 #include "ui/gfx/size_conversions.h" |
22 | 25 |
26 namespace { | |
27 | |
28 bool CoreAnimationIsEnabled() { | |
29 static bool is_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | |
30 switches::kUseCoreAnimation); | |
31 return is_enabled; | |
32 } | |
33 | |
34 } | |
35 | |
23 using content::WebContents; | 36 using content::WebContents; |
24 | 37 |
25 @interface DevToolsContainerView : BaseView { | 38 @interface DevToolsContainerView : BaseView { |
26 DevToolsContentsResizingStrategy strategy_; | 39 DevToolsContentsResizingStrategy strategy_; |
27 | 40 |
28 // Weak references. Ownership via -subviews. | 41 // Weak references. Ownership via -subviews. |
29 NSView* devToolsView_; | 42 NSView* devToolsView_; |
30 NSView* contentsView_; | 43 NSView* contentsView_; |
31 } | 44 } |
32 | 45 |
(...skipping 15 matching lines...) Expand all Loading... | |
48 | 61 |
49 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { | 62 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { |
50 [self adjustSubviews]; | 63 [self adjustSubviews]; |
51 } | 64 } |
52 | 65 |
53 - (void)showDevTools:(NSView*)devToolsView { | 66 - (void)showDevTools:(NSView*)devToolsView { |
54 NSArray* subviews = [self subviews]; | 67 NSArray* subviews = [self subviews]; |
55 DCHECK_EQ(1u, [subviews count]); | 68 DCHECK_EQ(1u, [subviews count]); |
56 contentsView_ = [subviews objectAtIndex:0]; | 69 contentsView_ = [subviews objectAtIndex:0]; |
57 devToolsView_ = devToolsView; | 70 devToolsView_ = devToolsView; |
58 // Place DevTools under contents. | 71 if (CoreAnimationIsEnabled()) { |
dgozman
2014/02/20 21:29:51
Do you plan to discard the old without-core-animat
ccameron
2014/02/20 21:31:10
Yes, hopefully all non-CA code will be deleted bef
| |
59 [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil]; | 72 // Make sure we do not draw any transient arrangements of views. |
73 gfx::ScopedNSDisableScreenUpdates disabler; | |
74 [self replaceSubview:contentsView_ with:devToolsView_]; | |
75 [devToolsView_ addSubview:contentsView_]; | |
76 } else { | |
77 // Place DevTools under contents. | |
78 [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil]; | |
79 } | |
60 } | 80 } |
61 | 81 |
62 - (void)hideDevTools { | 82 - (void)hideDevTools { |
63 DCHECK_EQ(2u, [[self subviews] count]); | 83 DCHECK_EQ(2u, [[self subviews] count]); |
64 [devToolsView_ removeFromSuperview]; | 84 if (CoreAnimationIsEnabled()) { |
85 // Make sure we do not draw any transient arrangements of views. | |
86 gfx::ScopedNSDisableScreenUpdates disabler; | |
87 [contentsView_ removeFromSuperview]; | |
88 [self replaceSubview:devToolsView_ with:contentsView_]; | |
89 } else { | |
90 [devToolsView_ removeFromSuperview]; | |
91 } | |
65 contentsView_ = nil; | 92 contentsView_ = nil; |
66 devToolsView_ = nil; | 93 devToolsView_ = nil; |
67 } | 94 } |
68 | 95 |
69 - (void)adjustSubviews { | 96 - (void)adjustSubviews { |
70 if (![[self subviews] count]) | 97 if (![[self subviews] count]) |
71 return; | 98 return; |
72 | 99 |
73 if (!devToolsView_) { | 100 if (!devToolsView_) { |
74 DCHECK_EQ(1u, [[self subviews] count]); | 101 DCHECK_EQ(1u, [[self subviews] count]); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 | 138 |
112 - (NSView*)view { | 139 - (NSView*)view { |
113 return devToolsContainerView_.get(); | 140 return devToolsContainerView_.get(); |
114 } | 141 } |
115 | 142 |
116 - (void)updateDevToolsForWebContents:(WebContents*)contents | 143 - (void)updateDevToolsForWebContents:(WebContents*)contents |
117 withProfile:(Profile*)profile { | 144 withProfile:(Profile*)profile { |
118 DevToolsWindow* newDevToolsWindow = contents ? | 145 DevToolsWindow* newDevToolsWindow = contents ? |
119 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL; | 146 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL; |
120 | 147 |
148 // Make sure we do not draw any transient arrangements of views. | |
149 gfx::ScopedNSDisableScreenUpdates disabler; | |
121 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow; | 150 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow; |
122 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow; | 151 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow; |
123 | 152 |
124 if (shouldHide) | 153 if (shouldHide) |
125 [self hideDevToolsView]; | 154 [self hideDevToolsView]; |
126 | 155 |
127 devToolsWindow_ = newDevToolsWindow; | 156 devToolsWindow_ = newDevToolsWindow; |
128 if (devToolsWindow_) { | 157 if (devToolsWindow_) { |
129 const DevToolsContentsResizingStrategy& strategy = | 158 const DevToolsContentsResizingStrategy& strategy = |
130 devToolsWindow_->GetContentsResizingStrategy(); | 159 devToolsWindow_->GetContentsResizingStrategy(); |
131 devToolsWindow_->web_contents()->GetView()->SetOverlayView( | 160 devToolsWindow_->web_contents()->GetView()->SetOverlayView( |
132 contents->GetView(), | 161 contents->GetView(), |
133 gfx::Point(strategy.insets().left(), strategy.insets().top())); | 162 gfx::Point(strategy.insets().left(), strategy.insets().top())); |
134 [devToolsContainerView_ setContentsResizingStrategy:strategy]; | 163 [devToolsContainerView_ setContentsResizingStrategy:strategy]; |
135 } else { | 164 } else { |
136 DevToolsContentsResizingStrategy zeroStrategy; | 165 DevToolsContentsResizingStrategy zeroStrategy; |
137 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy]; | 166 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy]; |
138 } | 167 } |
139 | 168 |
140 if (shouldShow) | 169 if (shouldShow) |
141 [self showDevToolsView]; | 170 [self showDevToolsView]; |
142 | 171 |
143 [devToolsContainerView_ adjustSubviews]; | 172 [devToolsContainerView_ adjustSubviews]; |
144 if (shouldHide || shouldShow) | |
145 [[devToolsContainerView_ window] disableScreenUpdatesUntilFlush]; | |
146 } | 173 } |
147 | 174 |
148 - (void)showDevToolsView { | 175 - (void)showDevToolsView { |
149 focusTracker_.reset( | 176 focusTracker_.reset( |
150 [[FocusTracker alloc] initWithWindow:[devToolsContainerView_ window]]); | 177 [[FocusTracker alloc] initWithWindow:[devToolsContainerView_ window]]); |
151 | 178 |
152 // |devToolsView| is a WebContentsViewCocoa object, whose ViewID was | 179 // |devToolsView| is a WebContentsViewCocoa object, whose ViewID was |
153 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 180 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
154 // VIEW_ID_DEV_TOOLS_DOCKED here. | 181 // VIEW_ID_DEV_TOOLS_DOCKED here. |
155 NSView* devToolsView = | 182 NSView* devToolsView = |
156 devToolsWindow_->web_contents()->GetView()->GetNativeView(); | 183 devToolsWindow_->web_contents()->GetView()->GetNativeView(); |
157 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); | 184 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); |
158 | 185 |
159 [devToolsContainerView_ showDevTools:devToolsView]; | 186 [devToolsContainerView_ showDevTools:devToolsView]; |
160 } | 187 } |
161 | 188 |
162 - (void)hideDevToolsView { | 189 - (void)hideDevToolsView { |
163 devToolsWindow_->web_contents()->GetView()->RemoveOverlayView(); | 190 devToolsWindow_->web_contents()->GetView()->RemoveOverlayView(); |
164 [devToolsContainerView_ hideDevTools]; | 191 [devToolsContainerView_ hideDevTools]; |
165 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]]; | 192 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]]; |
166 focusTracker_.reset(); | 193 focusTracker_.reset(); |
167 } | 194 } |
168 | 195 |
169 @end | 196 @end |
OLD | NEW |