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

Side by Side Diff: ui/views/controls/webview/webview.cc

Issue 2654413002: Stretching NativeViewHost, and misc tab capture fixes.
Patch Set: Gettin' it all working on ui/cocoa and MacViews too. Created 3 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
« no previous file with comments | « ui/views/controls/native/native_view_host_wrapper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "ui/views/controls/webview/webview.h" 5 #include "ui/views/controls/webview/webview.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/public/browser/browser_accessibility_state.h" 10 #include "content/public/browser/browser_accessibility_state.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // will engage the special layout/sizing behavior. 131 // will engage the special layout/sizing behavior.
132 gfx::Rect holder_bounds(bounds().size()); 132 gfx::Rect holder_bounds(bounds().size());
133 if (!embed_fullscreen_widget_mode_enabled_ || 133 if (!embed_fullscreen_widget_mode_enabled_ ||
134 !web_contents() || 134 !web_contents() ||
135 web_contents()->GetCapturerCount() == 0 || 135 web_contents()->GetCapturerCount() == 0 ||
136 web_contents()->GetPreferredSize().IsEmpty() || 136 web_contents()->GetPreferredSize().IsEmpty() ||
137 !(is_embedding_fullscreen_widget_ || 137 !(is_embedding_fullscreen_widget_ ||
138 (web_contents()->GetDelegate() && 138 (web_contents()->GetDelegate() &&
139 web_contents()->GetDelegate()-> 139 web_contents()->GetDelegate()->
140 IsFullscreenForTabOrPending(web_contents())))) { 140 IsFullscreenForTabOrPending(web_contents())))) {
141 holder_->SetRenderingSize(gfx::Size());
141 holder_->SetBoundsRect(holder_bounds); 142 holder_->SetBoundsRect(holder_bounds);
142 return; 143 return;
143 } 144 }
144 145
145 // Size the holder to the capture video resolution and center it. If this 146 // For screen-captured fullscreened content, scale the |holder_| to fit within
146 // WebView is not large enough to contain the holder at the preferred size, 147 // this View and center it.
147 // scale down to fit (preserving aspect ratio).
148 const gfx::Size capture_size = web_contents()->GetPreferredSize(); 148 const gfx::Size capture_size = web_contents()->GetPreferredSize();
149 if (capture_size.width() <= holder_bounds.width() && 149 const int64_t x =
150 capture_size.height() <= holder_bounds.height()) { 150 static_cast<int64_t>(capture_size.width()) * holder_bounds.height();
151 // No scaling, just centering. 151 const int64_t y =
152 holder_bounds.ClampToCenteredSize(capture_size); 152 static_cast<int64_t>(capture_size.height()) * holder_bounds.width();
153 if (y < x) {
154 holder_bounds.ClampToCenteredSize(gfx::Size(
155 holder_bounds.width(), static_cast<int>(y / capture_size.width())));
153 } else { 156 } else {
154 // Scale down, preserving aspect ratio, and center. 157 holder_bounds.ClampToCenteredSize(gfx::Size(
155 // TODO(miu): This is basically media::ComputeLetterboxRegion(), and it 158 static_cast<int>(x / capture_size.height()), holder_bounds.height()));
156 // looks like others have written this code elsewhere. Let's considate
157 // into a shared function ui/gfx/geometry or around there.
158 const int64_t x =
159 static_cast<int64_t>(capture_size.width()) * holder_bounds.height();
160 const int64_t y =
161 static_cast<int64_t>(capture_size.height()) * holder_bounds.width();
162 if (y < x) {
163 holder_bounds.ClampToCenteredSize(gfx::Size(
164 holder_bounds.width(), static_cast<int>(y / capture_size.width())));
165 } else {
166 holder_bounds.ClampToCenteredSize(gfx::Size(
167 static_cast<int>(x / capture_size.height()), holder_bounds.height()));
168 }
169 } 159 }
170 160 holder_->SetRenderingSize(capture_size);
171 holder_->SetBoundsRect(holder_bounds); 161 holder_->SetBoundsRect(holder_bounds);
172 } 162 }
173 163
174 void WebView::ViewHierarchyChanged( 164 void WebView::ViewHierarchyChanged(
175 const ViewHierarchyChangedDetails& details) { 165 const ViewHierarchyChangedDetails& details) {
176 if (details.is_add) 166 if (details.is_add)
177 AttachWebContents(); 167 AttachWebContents();
178 } 168 }
179 169
180 bool WebView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { 170 bool WebView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (!contents) { 373 if (!contents) {
384 content::WebContents::CreateParams create_params( 374 content::WebContents::CreateParams create_params(
385 browser_context, NULL); 375 browser_context, NULL);
386 return content::WebContents::Create(create_params); 376 return content::WebContents::Create(create_params);
387 } 377 }
388 378
389 return contents; 379 return contents;
390 } 380 }
391 381
392 } // namespace views 382 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/native/native_view_host_wrapper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698