| 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 #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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 : host_(widget_host), | 185 : host_(widget_host), |
| 186 needs_begin_frame_(false), | 186 needs_begin_frame_(false), |
| 187 is_showing_(!widget_host->is_hidden()), | 187 is_showing_(!widget_host->is_hidden()), |
| 188 content_view_core_(NULL), | 188 content_view_core_(NULL), |
| 189 ime_adapter_android_(this), | 189 ime_adapter_android_(this), |
| 190 cached_background_color_(SK_ColorWHITE), | 190 cached_background_color_(SK_ColorWHITE), |
| 191 last_output_surface_id_(kUndefinedOutputSurfaceId), | 191 last_output_surface_id_(kUndefinedOutputSurfaceId), |
| 192 weak_ptr_factory_(this), | 192 weak_ptr_factory_(this), |
| 193 overscroll_effect_enabled_(!CommandLine::ForCurrentProcess()->HasSwitch( | 193 overscroll_effect_enabled_(!CommandLine::ForCurrentProcess()->HasSwitch( |
| 194 switches::kDisableOverscrollEdgeEffect)), | 194 switches::kDisableOverscrollEdgeEffect)), |
| 195 overscroll_effect_(OverscrollGlow::Create(overscroll_effect_enabled_)), | |
| 196 gesture_provider_(CreateGestureProviderConfig(), this), | 195 gesture_provider_(CreateGestureProviderConfig(), this), |
| 197 gesture_text_selector_(this), | 196 gesture_text_selector_(this), |
| 198 touch_scrolling_(false), | 197 touch_scrolling_(false), |
| 199 potentially_active_fling_count_(0), | 198 potentially_active_fling_count_(0), |
| 200 flush_input_requested_(false), | 199 flush_input_requested_(false), |
| 201 accelerated_surface_route_id_(0), | 200 accelerated_surface_route_id_(0), |
| 202 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( | 201 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( |
| 203 widget_host->GetProcess()->GetID(), | 202 widget_host->GetProcess()->GetID(), |
| 204 widget_host->GetRoutingID()) != NULL), | 203 widget_host->GetRoutingID()) != NULL), |
| 205 frame_evictor_(new DelegatedFrameEvictor(this)), | 204 frame_evictor_(new DelegatedFrameEvictor(this)), |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 void RenderWidgetHostViewAndroid::MovePluginWindows( | 360 void RenderWidgetHostViewAndroid::MovePluginWindows( |
| 362 const std::vector<WebPluginGeometry>& moves) { | 361 const std::vector<WebPluginGeometry>& moves) { |
| 363 // We don't have plugin windows on Android. Do nothing. Note: this is called | 362 // We don't have plugin windows on Android. Do nothing. Note: this is called |
| 364 // from RenderWidgetHost::OnUpdateRect which is itself invoked while | 363 // from RenderWidgetHost::OnUpdateRect which is itself invoked while |
| 365 // processing the corresponding message from Renderer. | 364 // processing the corresponding message from Renderer. |
| 366 } | 365 } |
| 367 | 366 |
| 368 void RenderWidgetHostViewAndroid::Focus() { | 367 void RenderWidgetHostViewAndroid::Focus() { |
| 369 host_->Focus(); | 368 host_->Focus(); |
| 370 host_->SetInputMethodActive(true); | 369 host_->SetInputMethodActive(true); |
| 371 if (overscroll_effect_enabled_) | 370 if (overscroll_effect_) |
| 372 overscroll_effect_->Enable(); | 371 overscroll_effect_->Enable(); |
| 373 } | 372 } |
| 374 | 373 |
| 375 void RenderWidgetHostViewAndroid::Blur() { | 374 void RenderWidgetHostViewAndroid::Blur() { |
| 376 host_->ExecuteEditCommand("Unselect", ""); | 375 host_->ExecuteEditCommand("Unselect", ""); |
| 377 host_->SetInputMethodActive(false); | 376 host_->SetInputMethodActive(false); |
| 378 host_->Blur(); | 377 host_->Blur(); |
| 379 overscroll_effect_->Disable(); | 378 if (overscroll_effect_) |
| 379 overscroll_effect_->Disable(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 bool RenderWidgetHostViewAndroid::HasFocus() const { | 382 bool RenderWidgetHostViewAndroid::HasFocus() const { |
| 383 if (!content_view_core_) | 383 if (!content_view_core_) |
| 384 return false; // ContentViewCore not created yet. | 384 return false; // ContentViewCore not created yet. |
| 385 | 385 |
| 386 return content_view_core_->HasFocus(); | 386 return content_view_core_->HasFocus(); |
| 387 } | 387 } |
| 388 | 388 |
| 389 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 389 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 // Calculate the content size. This should be 0 if the texture_size is 0. | 922 // Calculate the content size. This should be 0 if the texture_size is 0. |
| 923 gfx::Vector2dF offset; | 923 gfx::Vector2dF offset; |
| 924 if (texture_size_in_layer_.GetArea() > 0) | 924 if (texture_size_in_layer_.GetArea() > 0) |
| 925 offset = frame_metadata.location_bar_content_translation; | 925 offset = frame_metadata.location_bar_content_translation; |
| 926 offset.set_y(offset.y() + frame_metadata.overdraw_bottom_height); | 926 offset.set_y(offset.y() + frame_metadata.overdraw_bottom_height); |
| 927 offset.Scale(frame_metadata.device_scale_factor); | 927 offset.Scale(frame_metadata.device_scale_factor); |
| 928 content_size_in_layer_ = | 928 content_size_in_layer_ = |
| 929 gfx::Size(texture_size_in_layer_.width() - offset.x(), | 929 gfx::Size(texture_size_in_layer_.width() - offset.x(), |
| 930 texture_size_in_layer_.height() - offset.y()); | 930 texture_size_in_layer_.height() - offset.y()); |
| 931 | 931 |
| 932 overscroll_effect_->UpdateDisplayParameters( | 932 if (overscroll_effect_) { |
| 933 CreateOverscrollDisplayParameters(frame_metadata)); | 933 overscroll_effect_->UpdateDisplayParameters( |
| 934 CreateOverscrollDisplayParameters(frame_metadata)); |
| 935 } |
| 934 } | 936 } |
| 935 | 937 |
| 936 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | 938 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
| 937 uint32 output_surface_id, | 939 uint32 output_surface_id, |
| 938 scoped_ptr<cc::CompositorFrame> frame) { | 940 scoped_ptr<cc::CompositorFrame> frame) { |
| 939 if (!frame->delegated_frame_data) { | 941 if (!frame->delegated_frame_data) { |
| 940 LOG(ERROR) << "Non-delegated renderer path no longer supported"; | 942 LOG(ERROR) << "Non-delegated renderer path no longer supported"; |
| 941 return; | 943 return; |
| 942 } | 944 } |
| 943 | 945 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 NOTREACHED() << "Need --composite-to-mailbox or --enable-delegated-renderer"; | 1138 NOTREACHED() << "Need --composite-to-mailbox or --enable-delegated-renderer"; |
| 1137 } | 1139 } |
| 1138 | 1140 |
| 1139 void RenderWidgetHostViewAndroid::AttachLayers() { | 1141 void RenderWidgetHostViewAndroid::AttachLayers() { |
| 1140 if (!content_view_core_) | 1142 if (!content_view_core_) |
| 1141 return; | 1143 return; |
| 1142 if (!layer_.get()) | 1144 if (!layer_.get()) |
| 1143 return; | 1145 return; |
| 1144 | 1146 |
| 1145 content_view_core_->AttachLayer(layer_); | 1147 content_view_core_->AttachLayer(layer_); |
| 1146 if (overscroll_effect_enabled_) | 1148 if (overscroll_effect_) |
| 1147 overscroll_effect_->Enable(); | 1149 overscroll_effect_->Enable(); |
| 1148 layer_->SetHideLayerAndSubtree(!is_showing_); | 1150 layer_->SetHideLayerAndSubtree(!is_showing_); |
| 1149 } | 1151 } |
| 1150 | 1152 |
| 1151 void RenderWidgetHostViewAndroid::RemoveLayers() { | 1153 void RenderWidgetHostViewAndroid::RemoveLayers() { |
| 1152 if (!content_view_core_) | 1154 if (!content_view_core_) |
| 1153 return; | 1155 return; |
| 1154 | 1156 |
| 1155 if (!layer_.get()) | 1157 if (!layer_.get()) |
| 1156 return; | 1158 return; |
| 1157 | 1159 |
| 1158 content_view_core_->RemoveLayer(layer_); | 1160 content_view_core_->RemoveLayer(layer_); |
| 1159 overscroll_effect_->Disable(); | 1161 if (overscroll_effect_) |
| 1162 overscroll_effect_->Disable(); |
| 1160 } | 1163 } |
| 1161 | 1164 |
| 1162 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1165 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
| 1163 bool needs_animate = overscroll_effect_->Animate(frame_time); | 1166 bool needs_animate = |
| 1167 overscroll_effect_ ? overscroll_effect_->Animate(frame_time) : false; |
| 1164 if (selection_controller_) | 1168 if (selection_controller_) |
| 1165 needs_animate |= selection_controller_->Animate(frame_time); | 1169 needs_animate |= selection_controller_->Animate(frame_time); |
| 1166 return needs_animate; | 1170 return needs_animate; |
| 1167 } | 1171 } |
| 1168 | 1172 |
| 1169 void RenderWidgetHostViewAndroid::OnContentScrollingChange() { | 1173 void RenderWidgetHostViewAndroid::OnContentScrollingChange() { |
| 1170 if (selection_controller_) | 1174 if (selection_controller_) |
| 1171 selection_controller_->SetTemporarilyHidden(IsContentScrolling()); | 1175 selection_controller_->SetTemporarilyHidden(IsContentScrolling()); |
| 1172 } | 1176 } |
| 1173 | 1177 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 | 1358 |
| 1355 void RenderWidgetHostViewAndroid::SendMouseWheelEvent( | 1359 void RenderWidgetHostViewAndroid::SendMouseWheelEvent( |
| 1356 const blink::WebMouseWheelEvent& event) { | 1360 const blink::WebMouseWheelEvent& event) { |
| 1357 if (host_) | 1361 if (host_) |
| 1358 host_->ForwardWheelEvent(event); | 1362 host_->ForwardWheelEvent(event); |
| 1359 } | 1363 } |
| 1360 | 1364 |
| 1361 void RenderWidgetHostViewAndroid::SendGestureEvent( | 1365 void RenderWidgetHostViewAndroid::SendGestureEvent( |
| 1362 const blink::WebGestureEvent& event) { | 1366 const blink::WebGestureEvent& event) { |
| 1363 // Sending a gesture that may trigger overscroll should resume the effect. | 1367 // Sending a gesture that may trigger overscroll should resume the effect. |
| 1364 if (overscroll_effect_enabled_) | 1368 if (overscroll_effect_) |
| 1365 overscroll_effect_->Enable(); | 1369 overscroll_effect_->Enable(); |
| 1366 | 1370 |
| 1367 if (host_) | 1371 if (host_) |
| 1368 host_->ForwardGestureEventWithLatencyInfo(event, CreateLatencyInfo(event)); | 1372 host_->ForwardGestureEventWithLatencyInfo(event, CreateLatencyInfo(event)); |
| 1369 } | 1373 } |
| 1370 | 1374 |
| 1371 void RenderWidgetHostViewAndroid::MoveCaret(const gfx::Point& point) { | 1375 void RenderWidgetHostViewAndroid::MoveCaret(const gfx::Point& point) { |
| 1372 if (host_) | 1376 if (host_) |
| 1373 host_->MoveCaret(point); | 1377 host_->MoveCaret(point); |
| 1374 } | 1378 } |
| 1375 | 1379 |
| 1376 void RenderWidgetHostViewAndroid::HideTextHandles() { | 1380 void RenderWidgetHostViewAndroid::HideTextHandles() { |
| 1377 if (selection_controller_) | 1381 if (selection_controller_) |
| 1378 selection_controller_->HideAndDisallowShowingAutomatically(); | 1382 selection_controller_->HideAndDisallowShowingAutomatically(); |
| 1379 } | 1383 } |
| 1380 | 1384 |
| 1381 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { | 1385 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { |
| 1382 return cached_background_color_; | 1386 return cached_background_color_; |
| 1383 } | 1387 } |
| 1384 | 1388 |
| 1385 void RenderWidgetHostViewAndroid::DidOverscroll( | 1389 void RenderWidgetHostViewAndroid::DidOverscroll( |
| 1386 const DidOverscrollParams& params) { | 1390 const DidOverscrollParams& params) { |
| 1387 if (!content_view_core_ || !layer_ || !is_showing_) | 1391 if (!content_view_core_ || !layer_ || !is_showing_) |
| 1388 return; | 1392 return; |
| 1389 | 1393 |
| 1390 const float device_scale_factor = content_view_core_->GetDpiScale(); | 1394 const float device_scale_factor = content_view_core_->GetDpiScale(); |
| 1391 if (overscroll_effect_->OnOverscrolled( | 1395 |
| 1396 if (overscroll_effect_ && |
| 1397 overscroll_effect_->OnOverscrolled( |
| 1392 content_view_core_->GetLayer(), | 1398 content_view_core_->GetLayer(), |
| 1393 base::TimeTicks::Now(), | 1399 base::TimeTicks::Now(), |
| 1394 gfx::ScaleVector2d(params.accumulated_overscroll, | 1400 gfx::ScaleVector2d(params.accumulated_overscroll, |
| 1395 device_scale_factor), | 1401 device_scale_factor), |
| 1396 gfx::ScaleVector2d(params.latest_overscroll_delta, | 1402 gfx::ScaleVector2d(params.latest_overscroll_delta, |
| 1397 device_scale_factor), | 1403 device_scale_factor), |
| 1398 gfx::ScaleVector2d(params.current_fling_velocity, | 1404 gfx::ScaleVector2d(params.current_fling_velocity, |
| 1399 device_scale_factor))) { | 1405 device_scale_factor))) { |
| 1400 SetNeedsAnimate(); | 1406 SetNeedsAnimate(); |
| 1401 } | 1407 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 observing_root_window_ = true; | 1454 observing_root_window_ = true; |
| 1449 if (needs_begin_frame_) | 1455 if (needs_begin_frame_) |
| 1450 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1456 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
| 1451 } | 1457 } |
| 1452 | 1458 |
| 1453 if (resize) | 1459 if (resize) |
| 1454 WasResized(); | 1460 WasResized(); |
| 1455 | 1461 |
| 1456 if (!selection_controller_) | 1462 if (!selection_controller_) |
| 1457 selection_controller_.reset(new TouchSelectionController(this)); | 1463 selection_controller_.reset(new TouchSelectionController(this)); |
| 1464 |
| 1465 if (!content_view_core_) { |
| 1466 overscroll_effect_.reset(); |
| 1467 } else if (overscroll_effect_enabled_ && !overscroll_effect_) { |
| 1468 DCHECK(content_view_core_->GetWindowAndroid()->GetCompositor()); |
| 1469 overscroll_effect_ = |
| 1470 OverscrollGlow::Create(&content_view_core_->GetWindowAndroid() |
| 1471 ->GetCompositor() |
| 1472 ->GetSystemUIResourceManager()); |
| 1473 } |
| 1458 } | 1474 } |
| 1459 | 1475 |
| 1460 void RenderWidgetHostViewAndroid::RunAckCallbacks() { | 1476 void RenderWidgetHostViewAndroid::RunAckCallbacks() { |
| 1461 while (!ack_callbacks_.empty()) { | 1477 while (!ack_callbacks_.empty()) { |
| 1462 ack_callbacks_.front().Run(); | 1478 ack_callbacks_.front().Run(); |
| 1463 ack_callbacks_.pop(); | 1479 ack_callbacks_.pop(); |
| 1464 } | 1480 } |
| 1465 } | 1481 } |
| 1466 | 1482 |
| 1467 void RenderWidgetHostViewAndroid::OnGestureEvent( | 1483 void RenderWidgetHostViewAndroid::OnGestureEvent( |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 results->orientationAngle = display.RotationAsDegree(); | 1671 results->orientationAngle = display.RotationAsDegree(); |
| 1656 results->orientationType = | 1672 results->orientationType = |
| 1657 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1673 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
| 1658 gfx::DeviceDisplayInfo info; | 1674 gfx::DeviceDisplayInfo info; |
| 1659 results->depth = info.GetBitsPerPixel(); | 1675 results->depth = info.GetBitsPerPixel(); |
| 1660 results->depthPerComponent = info.GetBitsPerComponent(); | 1676 results->depthPerComponent = info.GetBitsPerComponent(); |
| 1661 results->isMonochrome = (results->depthPerComponent == 0); | 1677 results->isMonochrome = (results->depthPerComponent == 0); |
| 1662 } | 1678 } |
| 1663 | 1679 |
| 1664 } // namespace content | 1680 } // namespace content |
| OLD | NEW |