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