Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 maximum_zoom_level_(ZoomFactorToZoomLevel(kMaxTextSizeMultiplier)), | 349 maximum_zoom_level_(ZoomFactorToZoomLevel(kMaxTextSizeMultiplier)), |
| 350 zoom_factor_for_device_scale_factor_(0.f), | 350 zoom_factor_for_device_scale_factor_(0.f), |
| 351 maximum_legible_scale_(1), | 351 maximum_legible_scale_(1), |
| 352 double_tap_zoom_page_scale_factor_(0), | 352 double_tap_zoom_page_scale_factor_(0), |
| 353 double_tap_zoom_pending_(false), | 353 double_tap_zoom_pending_(false), |
| 354 enable_fake_page_scale_animation_for_testing_(false), | 354 enable_fake_page_scale_animation_for_testing_(false), |
| 355 fake_page_scale_animation_page_scale_factor_(0), | 355 fake_page_scale_animation_page_scale_factor_(0), |
| 356 fake_page_scale_animation_use_anchor_(false), | 356 fake_page_scale_animation_use_anchor_(false), |
| 357 compositor_device_scale_factor_override_(0), | 357 compositor_device_scale_factor_override_(0), |
| 358 suppress_next_keypress_event_(false), | 358 suppress_next_keypress_event_(false), |
| 359 ime_accept_events_(true), | |
| 360 dev_tools_emulator_(nullptr), | 359 dev_tools_emulator_(nullptr), |
| 361 tabs_to_links_(false), | 360 tabs_to_links_(false), |
| 362 layer_tree_view_(nullptr), | 361 layer_tree_view_(nullptr), |
| 363 root_layer_(nullptr), | 362 root_layer_(nullptr), |
| 364 root_graphics_layer_(nullptr), | 363 root_graphics_layer_(nullptr), |
| 365 visual_viewport_container_layer_(nullptr), | 364 visual_viewport_container_layer_(nullptr), |
| 366 matches_heuristics_for_gpu_rasterization_(false), | 365 matches_heuristics_for_gpu_rasterization_(false), |
| 367 fling_modifier_(0), | 366 fling_modifier_(0), |
| 368 fling_source_device_(kWebGestureDeviceUninitialized), | 367 fling_source_device_(kWebGestureDeviceUninitialized), |
| 369 fullscreen_controller_(FullscreenController::Create(this)), | 368 fullscreen_controller_(FullscreenController::Create(this)), |
| (...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2282 page_->SetIsCursorVisible(is_visible); | 2281 page_->SetIsCursorVisible(is_visible); |
| 2283 } | 2282 } |
| 2284 | 2283 |
| 2285 void WebViewImpl::MouseCaptureLost() { | 2284 void WebViewImpl::MouseCaptureLost() { |
| 2286 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this); | 2285 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this); |
| 2287 mouse_capture_node_ = nullptr; | 2286 mouse_capture_node_ = nullptr; |
| 2288 } | 2287 } |
| 2289 | 2288 |
| 2290 void WebViewImpl::SetFocus(bool enable) { | 2289 void WebViewImpl::SetFocus(bool enable) { |
| 2291 page_->GetFocusController().SetFocused(enable); | 2290 page_->GetFocusController().SetFocused(enable); |
| 2291 LocalFrame* focused_frame = page_->GetFocusController().FocusedFrame(); | |
| 2292 if (enable) { | 2292 if (enable) { |
| 2293 page_->GetFocusController().SetActive(true); | 2293 page_->GetFocusController().SetActive(true); |
| 2294 LocalFrame* focused_frame = page_->GetFocusController().FocusedFrame(); | |
| 2295 if (focused_frame) { | 2294 if (focused_frame) { |
| 2296 Element* element = focused_frame->GetDocument()->FocusedElement(); | 2295 Element* element = focused_frame->GetDocument()->FocusedElement(); |
| 2297 if (element && focused_frame->Selection() | 2296 if (element && focused_frame->Selection() |
| 2298 .ComputeVisibleSelectionInDOMTreeDeprecated() | 2297 .ComputeVisibleSelectionInDOMTreeDeprecated() |
| 2299 .IsNone()) { | 2298 .IsNone()) { |
| 2300 // If the selection was cleared while the WebView was not | 2299 // If the selection was cleared while the WebView was not |
| 2301 // focused, then the focus element shows with a focus ring but | 2300 // focused, then the focus element shows with a focus ring but |
| 2302 // no caret and does respond to keyboard inputs. | 2301 // no caret and does respond to keyboard inputs. |
| 2303 focused_frame->GetDocument()->UpdateStyleAndLayoutTree(); | 2302 focused_frame->GetDocument()->UpdateStyleAndLayoutTree(); |
| 2304 if (element->IsTextControl()) { | 2303 if (element->IsTextControl()) { |
| 2305 element->UpdateFocusAppearance(SelectionBehaviorOnFocus::kRestore); | 2304 element->UpdateFocusAppearance(SelectionBehaviorOnFocus::kRestore); |
| 2306 } else if (HasEditableStyle(*element)) { | 2305 } else if (HasEditableStyle(*element)) { |
| 2307 // updateFocusAppearance() selects all the text of | 2306 // updateFocusAppearance() selects all the text of |
| 2308 // contentseditable DIVs. So we set the selection explicitly | 2307 // contentseditable DIVs. So we set the selection explicitly |
| 2309 // instead. Note that this has the side effect of moving the | 2308 // instead. Note that this has the side effect of moving the |
| 2310 // caret back to the beginning of the text. | 2309 // caret back to the beginning of the text. |
| 2311 Position position(element, 0); | 2310 Position position(element, 0); |
| 2312 focused_frame->Selection().SetSelection( | 2311 focused_frame->Selection().SetSelection( |
| 2313 SelectionInDOMTree::Builder().Collapse(position).Build()); | 2312 SelectionInDOMTree::Builder().Collapse(position).Build()); |
| 2314 } | 2313 } |
| 2315 } | 2314 } |
| 2315 // TODO(ekaramad): We need to figure out the right way to propagate page | |
| 2316 // focus to OOPIFs. Right now WebFrameWidgetImpl::SetFocus never gets | |
| 2317 // called (https://crbug.com/689777). | |
| 2318 WebLocalFrameBase::FromFrame(focused_frame->LocalFrameRoot()) | |
| 2319 ->FrameWidget() | |
| 2320 ->ime_accept_events_ = true; | |
|
alexmos
2017/06/15 02:53:06
Ugh, really hope we can clean this up soon. I agr
EhsanK
2017/06/16 19:25:14
Agreed. I have been meaning to get started on this
alexmos
2017/06/17 01:06:43
Sounds good. The other concern I remember with th
| |
| 2316 } | 2321 } |
| 2317 ime_accept_events_ = true; | |
| 2318 } else { | 2322 } else { |
| 2319 HidePopups(); | 2323 HidePopups(); |
| 2320 | 2324 |
| 2321 // Clear focus on the currently focused frame if any. | 2325 // Clear focus on the currently focused frame if any. |
| 2322 if (!page_) | 2326 if (!page_ || !focused_frame) |
| 2323 return; | 2327 return; |
| 2324 | 2328 |
| 2325 LocalFrame* frame = page_->MainFrame() && page_->MainFrame()->IsLocalFrame() | 2329 // Finish an ongoing composition to delete the composition node. |
| 2326 ? page_->DeprecatedLocalMainFrame() | 2330 if (focused_frame->GetInputMethodController().HasComposition()) { |
| 2327 : nullptr; | 2331 // TODO(editing-dev): The use of |
| 2328 if (!frame) | 2332 // updateStyleAndLayoutIgnorePendingStylesheets needs to be audited. |
| 2329 return; | 2333 // See http://crbug.com/590369 for more details. |
| 2334 focused_frame->GetDocument() | |
| 2335 ->UpdateStyleAndLayoutIgnorePendingStylesheets(); | |
| 2330 | 2336 |
| 2331 LocalFrame* focused_frame = FocusedLocalFrameInWidget(); | 2337 focused_frame->GetInputMethodController().FinishComposingText( |
| 2332 if (focused_frame) { | 2338 InputMethodController::kKeepSelection); |
| 2333 // Finish an ongoing composition to delete the composition node. | |
| 2334 if (focused_frame->GetInputMethodController().HasComposition()) { | |
| 2335 // TODO(editing-dev): The use of | |
| 2336 // updateStyleAndLayoutIgnorePendingStylesheets needs to be audited. | |
| 2337 // See http://crbug.com/590369 for more details. | |
| 2338 focused_frame->GetDocument() | |
| 2339 ->UpdateStyleAndLayoutIgnorePendingStylesheets(); | |
| 2340 | |
| 2341 focused_frame->GetInputMethodController().FinishComposingText( | |
| 2342 InputMethodController::kKeepSelection); | |
| 2343 } | 2339 } |
| 2344 ime_accept_events_ = false; | 2340 // TODO(ekaramad): We need to figure out the right way to propagate page |
| 2345 } | 2341 // focus to OOPIFs. Right now WebFrameWidgetImpl::SetFocus never gets |
| 2342 // called (https://crbug.com/689777). | |
| 2343 WebLocalFrameBase::FromFrame(focused_frame->LocalFrameRoot()) | |
| 2344 ->FrameWidget() | |
| 2345 ->ime_accept_events_ = false; | |
| 2346 } | 2346 } |
| 2347 } | 2347 } |
| 2348 | 2348 |
| 2349 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as | 2349 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as |
| 2350 // well. This code needs to be refactored (http://crbug.com/629721). | 2350 // well. This code needs to be refactored (http://crbug.com/629721). |
| 2351 WebRange WebViewImpl::CompositionRange() { | 2351 WebRange WebViewImpl::CompositionRange() { |
| 2352 LocalFrame* focused = FocusedLocalFrameAvailableForIme(); | 2352 if (!MainFrameImpl() || !MainFrameImpl()->FrameWidget()->ime_accept_events_) |
| 2353 return WebRange(); | |
| 2354 | |
| 2355 LocalFrame* focused = FocusedLocalFrameInWidget(); | |
| 2353 if (!focused) | 2356 if (!focused) |
| 2354 return WebRange(); | 2357 return WebRange(); |
| 2355 | 2358 |
| 2356 const EphemeralRange range = | 2359 const EphemeralRange range = |
| 2357 focused->GetInputMethodController().CompositionEphemeralRange(); | 2360 focused->GetInputMethodController().CompositionEphemeralRange(); |
| 2358 if (range.IsNull()) | 2361 if (range.IsNull()) |
| 2359 return WebRange(); | 2362 return WebRange(); |
| 2360 | 2363 |
| 2361 Element* editable = | 2364 Element* editable = |
| 2362 focused->Selection().RootEditableElementOrDocumentElement(); | 2365 focused->Selection().RootEditableElementOrDocumentElement(); |
| (...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4134 // TODO(oshima): Investigate if this should return the ScreenInfo's scale | 4137 // TODO(oshima): Investigate if this should return the ScreenInfo's scale |
| 4135 // factor rather than page's scale factor, which can be 1 in use-zoom-for-dsf | 4138 // factor rather than page's scale factor, which can be 1 in use-zoom-for-dsf |
| 4136 // mode. | 4139 // mode. |
| 4137 if (!GetPage()) | 4140 if (!GetPage()) |
| 4138 return 1; | 4141 return 1; |
| 4139 | 4142 |
| 4140 return GetPage()->DeviceScaleFactorDeprecated(); | 4143 return GetPage()->DeviceScaleFactorDeprecated(); |
| 4141 } | 4144 } |
| 4142 | 4145 |
| 4143 LocalFrame* WebViewImpl::FocusedLocalFrameInWidget() const { | 4146 LocalFrame* WebViewImpl::FocusedLocalFrameInWidget() const { |
| 4144 if (!MainFrameImpl()) | 4147 if (auto* frame = MainFrameImpl()) |
| 4145 return nullptr; | 4148 return frame->FrameWidget()->FocusedLocalFrame(); |
| 4146 | 4149 return nullptr; |
| 4147 LocalFrame* focused_frame = ToLocalFrame(FocusedCoreFrame()); | |
| 4148 if (focused_frame->LocalFrameRoot() != MainFrameImpl()->GetFrame()) | |
| 4149 return nullptr; | |
| 4150 return focused_frame; | |
| 4151 } | |
| 4152 | |
| 4153 LocalFrame* WebViewImpl::FocusedLocalFrameAvailableForIme() const { | |
| 4154 return ime_accept_events_ ? FocusedLocalFrameInWidget() : nullptr; | |
| 4155 } | 4150 } |
| 4156 | 4151 |
| 4157 } // namespace blink | 4152 } // namespace blink |
| OLD | NEW |