| 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_base.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "content/browser/accessibility/browser_accessibility_manager.h" | 9 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 10 #include "content/browser/gpu/gpu_data_manager_impl.h" | 10 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 11 #include "content/browser/renderer_host/input/synthetic_gesture_target_base.h" | 11 #include "content/browser/renderer_host/input/synthetic_gesture_target_base.h" |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 13 #include "content/browser/renderer_host/render_view_host_delegate.h" | |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 15 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 13 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h" | 15 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h" |
| 18 #include "content/common/content_switches_internal.h" | 16 #include "content/common/content_switches_internal.h" |
| 19 #include "content/common/input_messages.h" | |
| 20 #include "content/common/site_isolation_policy.h" | |
| 21 #include "content/common/text_input_state.h" | |
| 22 #include "content/common/view_messages.h" | |
| 23 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 17 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 24 #include "content/public/common/browser_plugin_guest_mode.h" | |
| 25 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| 26 #include "ui/gfx/geometry/point_conversions.h" | 19 #include "ui/gfx/geometry/point_conversions.h" |
| 27 #include "ui/gfx/geometry/size_conversions.h" | 20 #include "ui/gfx/geometry/size_conversions.h" |
| 28 #include "ui/gfx/geometry/size_f.h" | 21 #include "ui/gfx/geometry/size_f.h" |
| 29 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 30 | 23 |
| 31 namespace content { | 24 namespace content { |
| 32 | 25 |
| 33 namespace { | 26 namespace { |
| 34 | 27 |
| 35 // How many microseconds apart input events should be flushed. | 28 // How many microseconds apart input events should be flushed. |
| 36 const int kFlushInputRateInUs = 16666; | 29 const int kFlushInputRateInUs = 16666; |
| 37 | 30 |
| 38 } | 31 } |
| 39 | 32 |
| 40 RenderWidgetHostViewBase::RenderWidgetHostViewBase() | 33 RenderWidgetHostViewBase::RenderWidgetHostViewBase() |
| 41 : popup_type_(blink::WebPopupTypeNone), | 34 : popup_type_(blink::WebPopupTypeNone), |
| 42 background_color_(SK_ColorWHITE), | 35 background_color_(SK_ColorWHITE), |
| 43 mouse_locked_(false), | 36 mouse_locked_(false), |
| 44 showing_context_menu_(false), | 37 showing_context_menu_(false), |
| 45 selection_text_offset_(0), | 38 selection_text_offset_(0), |
| 46 selection_range_(gfx::Range::InvalidRange()), | 39 selection_range_(gfx::Range::InvalidRange()), |
| 47 current_device_scale_factor_(0), | 40 current_device_scale_factor_(0), |
| 48 current_display_rotation_(gfx::Display::ROTATE_0), | 41 current_display_rotation_(gfx::Display::ROTATE_0), |
| 49 pinch_zoom_enabled_(content::IsPinchToZoomEnabled()), | 42 pinch_zoom_enabled_(content::IsPinchToZoomEnabled()), |
| 50 renderer_frame_number_(0), | 43 renderer_frame_number_(0), |
| 51 text_input_state_(new TextInputState()), | |
| 52 weak_factory_(this) {} | 44 weak_factory_(this) {} |
| 53 | 45 |
| 54 RenderWidgetHostViewBase::~RenderWidgetHostViewBase() { | 46 RenderWidgetHostViewBase::~RenderWidgetHostViewBase() { |
| 55 DCHECK(!mouse_locked_); | 47 DCHECK(!mouse_locked_); |
| 56 // We call this here to guarantee that observers are notified before we go | 48 // We call this here to guarantee that observers are notified before we go |
| 57 // away. However, some subclasses may wish to call this earlier in their | 49 // away. However, some subclasses may wish to call this earlier in their |
| 58 // shutdown process, e.g. to force removal from | 50 // shutdown process, e.g. to force removal from |
| 59 // RenderWidgetHostInputEventRouter's surface map before relinquishing a | 51 // RenderWidgetHostInputEventRouter's surface map before relinquishing a |
| 60 // host pointer, as in RenderWidgetHostViewGuest. There is no harm in calling | 52 // host pointer, as in RenderWidgetHostViewGuest. There is no harm in calling |
| 61 // NotifyObserversAboutShutdown() twice, as the observers are required to | 53 // NotifyObserversAboutShutdown() twice, as the observers are required to |
| 62 // de-register on the first call, and so the second call does nothing. | 54 // de-register on the first call, and so the second call does nothing. |
| 63 NotifyObserversAboutShutdown(); | 55 NotifyObserversAboutShutdown(); |
| 64 } | 56 } |
| 65 | 57 |
| 66 void RenderWidgetHostViewBase::NotifyObserversAboutShutdown() { | 58 void RenderWidgetHostViewBase::NotifyObserversAboutShutdown() { |
| 67 // Note: RenderWidgetHostInputEventRouter is an observer, and uses the | 59 // Note: RenderWidgetHostInputEventRouter is an observer, and uses the |
| 68 // following notification to remove this view from its surface owners map. | 60 // following notification to remove this view from its surface owners map. |
| 69 FOR_EACH_OBSERVER(RenderWidgetHostViewBaseObserver, | 61 FOR_EACH_OBSERVER(RenderWidgetHostViewBaseObserver, |
| 70 observers_, | 62 observers_, |
| 71 OnRenderWidgetHostViewBaseDestroyed(this)); | 63 OnRenderWidgetHostViewBaseDestroyed(this)); |
| 72 // All observers are required to disconnect after they are notified. | 64 // All observers are required to disconnect after they are notified. |
| 73 DCHECK(!observers_.might_have_observers()); | 65 DCHECK(!observers_.might_have_observers()); |
| 74 } | 66 } |
| 75 | 67 |
| 76 void RenderWidgetHostViewBase::NotifyHostDelegateAboutShutdown() { | |
| 77 RenderWidgetHostImpl* host = | |
| 78 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | |
| 79 | |
| 80 if (!host || !host->delegate()) | |
| 81 return; | |
| 82 | |
| 83 bool has_active_text = text_input_state()->type != ui::TEXT_INPUT_TYPE_NONE; | |
| 84 text_input_state_.reset(new TextInputState()); | |
| 85 | |
| 86 host->delegate()->UpdateTextInputState(this, has_active_text); | |
| 87 } | |
| 88 | |
| 89 bool RenderWidgetHostViewBase::OnMessageReceived(const IPC::Message& msg){ | 68 bool RenderWidgetHostViewBase::OnMessageReceived(const IPC::Message& msg){ |
| 90 return false; | 69 return false; |
| 91 } | 70 } |
| 92 | 71 |
| 93 void RenderWidgetHostViewBase::SetBackgroundColor(SkColor color) { | 72 void RenderWidgetHostViewBase::SetBackgroundColor(SkColor color) { |
| 94 background_color_ = color; | 73 background_color_ = color; |
| 95 } | 74 } |
| 96 | 75 |
| 97 void RenderWidgetHostViewBase::SetBackgroundColorToDefault() { | 76 void RenderWidgetHostViewBase::SetBackgroundColorToDefault() { |
| 98 SetBackgroundColor(SK_ColorWHITE); | 77 SetBackgroundColor(SK_ColorWHITE); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 current_display_rotation_ == display.rotation()) { | 221 current_display_rotation_ == display.rotation()) { |
| 243 return false; | 222 return false; |
| 244 } | 223 } |
| 245 | 224 |
| 246 current_display_area_ = display.work_area(); | 225 current_display_area_ = display.work_area(); |
| 247 current_device_scale_factor_ = display.device_scale_factor(); | 226 current_device_scale_factor_ = display.device_scale_factor(); |
| 248 current_display_rotation_ = display.rotation(); | 227 current_display_rotation_ = display.rotation(); |
| 249 return true; | 228 return true; |
| 250 } | 229 } |
| 251 | 230 |
| 252 void RenderWidgetHostViewBase::TextInputStateChanged( | |
| 253 const TextInputState& params) { | |
| 254 bool text_input_state_changed = true; | |
| 255 #if !defined(OS_ANDROID) | |
| 256 if (params.type == text_input_state_->type && | |
| 257 params.can_compose_inline == text_input_state_->can_compose_inline | |
| 258 #if !defined(OS_MACOSX) | |
| 259 && params.mode == text_input_state_->mode && | |
| 260 params.flags == text_input_state_->flags | |
| 261 #endif | |
| 262 ) | |
| 263 text_input_state_changed = false; | |
| 264 #else | |
| 265 if (params.is_non_ime_change) { | |
| 266 // Sends an acknowledgement to the renderer of a processed IME event. | |
| 267 GetRenderWidgetHost()->Send( | |
| 268 new InputMsg_ImeEventAck(GetRenderWidgetHost()->GetRoutingID())); | |
| 269 } | |
| 270 #endif | |
| 271 | |
| 272 if (text_input_state_changed) { | |
| 273 *text_input_state_ = params; | |
| 274 RenderWidgetHostImpl* host = | |
| 275 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | |
| 276 if (host && host->delegate()) | |
| 277 host->delegate()->UpdateTextInputState(this, text_input_state_changed); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 base::WeakPtr<RenderWidgetHostViewBase> RenderWidgetHostViewBase::GetWeakPtr() { | 231 base::WeakPtr<RenderWidgetHostViewBase> RenderWidgetHostViewBase::GetWeakPtr() { |
| 282 return weak_factory_.GetWeakPtr(); | 232 return weak_factory_.GetWeakPtr(); |
| 283 } | 233 } |
| 284 | 234 |
| 285 std::unique_ptr<SyntheticGestureTarget> | 235 std::unique_ptr<SyntheticGestureTarget> |
| 286 RenderWidgetHostViewBase::CreateSyntheticGestureTarget() { | 236 RenderWidgetHostViewBase::CreateSyntheticGestureTarget() { |
| 287 RenderWidgetHostImpl* host = | 237 RenderWidgetHostImpl* host = |
| 288 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | 238 RenderWidgetHostImpl::From(GetRenderWidgetHost()); |
| 289 return std::unique_ptr<SyntheticGestureTarget>( | 239 return std::unique_ptr<SyntheticGestureTarget>( |
| 290 new SyntheticGestureTargetBase(host)); | 240 new SyntheticGestureTargetBase(host)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 394 |
| 445 bool RenderWidgetHostViewBase::IsChildFrameForTesting() const { | 395 bool RenderWidgetHostViewBase::IsChildFrameForTesting() const { |
| 446 return false; | 396 return false; |
| 447 } | 397 } |
| 448 | 398 |
| 449 cc::SurfaceId RenderWidgetHostViewBase::SurfaceIdForTesting() const { | 399 cc::SurfaceId RenderWidgetHostViewBase::SurfaceIdForTesting() const { |
| 450 return cc::SurfaceId(); | 400 return cc::SurfaceId(); |
| 451 } | 401 } |
| 452 | 402 |
| 453 } // namespace content | 403 } // namespace content |
| OLD | NEW |