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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2682593002: Refactor ContentViewClient (4/6) (Closed)
Patch Set: . 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
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 "content/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 393
394 gl_helper->CropScaleReadbackAndCleanMailbox( 394 gl_helper->CropScaleReadbackAndCleanMailbox(
395 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), 395 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(),
396 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, 396 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type,
397 base::Bind(&CopyFromCompositingSurfaceFinished, callback, 397 base::Bind(&CopyFromCompositingSurfaceFinished, callback,
398 base::Passed(&release_callback), base::Passed(&bitmap), 398 base::Passed(&release_callback), base::Passed(&bitmap),
399 start_time, base::Passed(&bitmap_pixels_lock), readback_lock), 399 start_time, base::Passed(&bitmap_pixels_lock), readback_lock),
400 display_compositor::GLHelper::SCALER_QUALITY_GOOD); 400 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
401 } 401 }
402 402
403 bool FloatEquals(float a, float b) {
404 return std::abs(a - b) < FLT_EPSILON;
405 }
406
403 } // namespace 407 } // namespace
404 408
405 void RenderWidgetHostViewAndroid::OnContextLost() { 409 void RenderWidgetHostViewAndroid::OnContextLost() {
406 std::unique_ptr<RenderWidgetHostIterator> widgets( 410 std::unique_ptr<RenderWidgetHostIterator> widgets(
407 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); 411 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
408 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 412 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
409 if (widget->GetView()) { 413 if (widget->GetView()) {
410 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) 414 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView())
411 ->OnLostResources(); 415 ->OnLostResources();
412 } 416 }
(...skipping 15 matching lines...) Expand all
428 cached_background_color_(SK_ColorWHITE), 432 cached_background_color_(SK_ColorWHITE),
429 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), 433 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
430 gesture_provider_(ui::GetGestureProviderConfig( 434 gesture_provider_(ui::GetGestureProviderConfig(
431 ui::GestureProviderConfigType::CURRENT_PLATFORM), 435 ui::GestureProviderConfigType::CURRENT_PLATFORM),
432 this), 436 this),
433 stylus_text_selector_(this), 437 stylus_text_selector_(this),
434 using_browser_compositor_(CompositorImpl::IsInitialized()), 438 using_browser_compositor_(CompositorImpl::IsInitialized()),
435 synchronous_compositor_client_(nullptr), 439 synchronous_compositor_client_(nullptr),
436 frame_evictor_(new DelegatedFrameEvictor(this)), 440 frame_evictor_(new DelegatedFrameEvictor(this)),
437 observing_root_window_(false), 441 observing_root_window_(false),
442 prev_top_shown_pix_(0.f),
443 prev_bottom_shown_pix_(0.f),
438 weak_ptr_factory_(this) { 444 weak_ptr_factory_(this) {
439 // Set the layer which will hold the content layer for this view. The content 445 // Set the layer which will hold the content layer for this view. The content
440 // layer is managed by the DelegatedFrameHost. 446 // layer is managed by the DelegatedFrameHost.
441 view_.SetLayer(cc::Layer::Create()); 447 view_.SetLayer(cc::Layer::Create());
442 if (using_browser_compositor_) { 448 if (using_browser_compositor_) {
443 // This FrameSinkId must be unique with ContextProviderFactory's FrameSinkId 449 // This FrameSinkId must be unique with ContextProviderFactory's FrameSinkId
444 // allocation. 450 // allocation.
445 // TODO(crbug.com/685777): Centralize allocation in one place for easier 451 // TODO(crbug.com/685777): Centralize allocation in one place for easier
446 // maintenance. 452 // maintenance.
447 cc::FrameSinkId frame_sink_id = cc::FrameSinkId( 453 cc::FrameSinkId frame_sink_id = cc::FrameSinkId(
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 791
786 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { 792 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
787 if (cached_background_color_ == color) 793 if (cached_background_color_ == color)
788 return; 794 return;
789 795
790 cached_background_color_ = color; 796 cached_background_color_ = color;
791 797
792 if (delegated_frame_host_) 798 if (delegated_frame_host_)
793 delegated_frame_host_->UpdateBackgroundColor(color); 799 delegated_frame_host_->UpdateBackgroundColor(color);
794 800
795 if (content_view_core_) 801 view_.OnBackgroundColorChanged(color);
796 content_view_core_->OnBackgroundColorChanged(color);
797 } 802 }
798 803
799 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { 804 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) {
800 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", 805 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames",
801 "needs_begin_frames", needs_begin_frames); 806 "needs_begin_frames", needs_begin_frames);
802 if (needs_begin_frames) 807 if (needs_begin_frames)
803 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME); 808 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME);
804 else 809 else
805 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME); 810 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME);
806 } 811 }
807 812
808 void RenderWidgetHostViewAndroid::OnStartContentIntent( 813 void RenderWidgetHostViewAndroid::OnStartContentIntent(
809 const GURL& content_url, bool is_main_frame) { 814 const GURL& content_url, bool is_main_frame) {
810 if (content_view_core_) 815 view_.StartContentIntent(content_url, is_main_frame);
811 content_view_core_->StartContentIntent(content_url, is_main_frame);
812 } 816 }
813 817
814 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( 818 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted(
815 const base::string16& text, 819 const base::string16& text,
816 const base::string16& html, 820 const base::string16& html,
817 const gfx::Rect rect) { 821 const gfx::Rect rect) {
818 if (content_view_core_) 822 if (content_view_core_)
819 content_view_core_->OnSmartClipDataExtracted(text, html, rect); 823 content_view_core_->OnSmartClipDataExtracted(text, html, rect);
820 } 824 }
821 825
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 selection_controller_->OnViewportChanged(viewport_rect); 1281 selection_controller_->OnViewportChanged(viewport_rect);
1278 } 1282 }
1279 1283
1280 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT 1284 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT
1281 : frame_metadata.root_background_color); 1285 : frame_metadata.root_background_color);
1282 1286
1283 view_.set_content_offset(gfx::Vector2dF(0.0f, 1287 view_.set_content_offset(gfx::Vector2dF(0.0f,
1284 frame_metadata.top_controls_height * 1288 frame_metadata.top_controls_height *
1285 frame_metadata.top_controls_shown_ratio)); 1289 frame_metadata.top_controls_shown_ratio));
1286 1290
1291 float dip_scale = ui::GetScaleFactorForNativeView(GetNativeView());
1292 float top_controls_pix = frame_metadata.top_controls_height * dip_scale;
1293 float top_shown_pix = top_controls_pix
1294 * frame_metadata.top_controls_shown_ratio;
1295 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_);
1296
1297 float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale;
1298 float bottom_shown_pix = bottom_controls_pix
1299 * frame_metadata.bottom_controls_shown_ratio;
1300 bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_);
1301
1302 if (top_changed) {
1303 float translate = top_shown_pix - top_controls_pix;
1304 view_.OnTopControlsChanged(translate, top_shown_pix);
1305 prev_top_shown_pix_ = top_shown_pix;
1306 }
1307 if (bottom_changed) {
1308 float translate = bottom_controls_pix - bottom_shown_pix;
1309 view_.OnBottomControlsChanged(translate, bottom_shown_pix);
1310 prev_bottom_shown_pix_ = bottom_shown_pix;
1311 }
1312
1287 // All offsets and sizes are in CSS pixels. 1313 // All offsets and sizes are in CSS pixels.
1288 content_view_core_->UpdateFrameInfo( 1314 content_view_core_->UpdateFrameInfo(
1289 frame_metadata.root_scroll_offset, 1315 frame_metadata.root_scroll_offset,
1290 frame_metadata.page_scale_factor, 1316 frame_metadata.page_scale_factor,
1291 gfx::Vector2dF(frame_metadata.min_page_scale_factor, 1317 gfx::Vector2dF(frame_metadata.min_page_scale_factor,
1292 frame_metadata.max_page_scale_factor), 1318 frame_metadata.max_page_scale_factor),
1293 frame_metadata.root_layer_size, 1319 frame_metadata.root_layer_size,
1294 frame_metadata.scrollable_viewport_size, 1320 frame_metadata.scrollable_viewport_size,
1295 frame_metadata.top_controls_height, 1321 frame_metadata.top_controls_height,
1296 frame_metadata.top_controls_shown_ratio, 1322 frame_metadata.top_controls_shown_ratio,
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2012 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
1987 if (!compositor) 2013 if (!compositor)
1988 return; 2014 return;
1989 2015
1990 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2016 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
1991 overscroll_refresh_handler, compositor, 2017 overscroll_refresh_handler, compositor,
1992 ui::GetScaleFactorForNativeView(GetNativeView())); 2018 ui::GetScaleFactorForNativeView(GetNativeView()));
1993 } 2019 }
1994 2020
1995 } // namespace content 2021 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698