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