Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2910233002: Do not fallback to FocusedOrMainFrame() in FocusedLocalFrameInWidget() (Closed)
Patch Set: Rebased Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 maximum_zoom_level_(ZoomFactorToZoomLevel(kMaxTextSizeMultiplier)), 343 maximum_zoom_level_(ZoomFactorToZoomLevel(kMaxTextSizeMultiplier)),
344 zoom_factor_for_device_scale_factor_(0.f), 344 zoom_factor_for_device_scale_factor_(0.f),
345 maximum_legible_scale_(1), 345 maximum_legible_scale_(1),
346 double_tap_zoom_page_scale_factor_(0), 346 double_tap_zoom_page_scale_factor_(0),
347 double_tap_zoom_pending_(false), 347 double_tap_zoom_pending_(false),
348 enable_fake_page_scale_animation_for_testing_(false), 348 enable_fake_page_scale_animation_for_testing_(false),
349 fake_page_scale_animation_page_scale_factor_(0), 349 fake_page_scale_animation_page_scale_factor_(0),
350 fake_page_scale_animation_use_anchor_(false), 350 fake_page_scale_animation_use_anchor_(false),
351 compositor_device_scale_factor_override_(0), 351 compositor_device_scale_factor_override_(0),
352 suppress_next_keypress_event_(false), 352 suppress_next_keypress_event_(false),
353 ime_accept_events_(true),
354 dev_tools_emulator_(nullptr), 353 dev_tools_emulator_(nullptr),
355 tabs_to_links_(false), 354 tabs_to_links_(false),
356 layer_tree_view_(nullptr), 355 layer_tree_view_(nullptr),
357 root_layer_(nullptr), 356 root_layer_(nullptr),
358 root_graphics_layer_(nullptr), 357 root_graphics_layer_(nullptr),
359 visual_viewport_container_layer_(nullptr), 358 visual_viewport_container_layer_(nullptr),
360 matches_heuristics_for_gpu_rasterization_(false), 359 matches_heuristics_for_gpu_rasterization_(false),
361 fling_modifier_(0), 360 fling_modifier_(0),
362 fling_source_device_(kWebGestureDeviceUninitialized), 361 fling_source_device_(kWebGestureDeviceUninitialized),
363 fullscreen_controller_(FullscreenController::Create(this)), 362 fullscreen_controller_(FullscreenController::Create(this)),
(...skipping 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 page_->SetIsCursorVisible(is_visible); 2258 page_->SetIsCursorVisible(is_visible);
2260 } 2259 }
2261 2260
2262 void WebViewImpl::MouseCaptureLost() { 2261 void WebViewImpl::MouseCaptureLost() {
2263 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this); 2262 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this);
2264 mouse_capture_node_ = nullptr; 2263 mouse_capture_node_ = nullptr;
2265 } 2264 }
2266 2265
2267 void WebViewImpl::SetFocus(bool enable) { 2266 void WebViewImpl::SetFocus(bool enable) {
2268 page_->GetFocusController().SetFocused(enable); 2267 page_->GetFocusController().SetFocused(enable);
2268 LocalFrame* focused_frame = page_->GetFocusController().FocusedFrame();
2269 if (enable) { 2269 if (enable) {
2270 page_->GetFocusController().SetActive(true); 2270 page_->GetFocusController().SetActive(true);
2271 LocalFrame* focused_frame = page_->GetFocusController().FocusedFrame();
2272 if (focused_frame) { 2271 if (focused_frame) {
2273 Element* element = focused_frame->GetDocument()->FocusedElement(); 2272 Element* element = focused_frame->GetDocument()->FocusedElement();
2274 if (element && focused_frame->Selection() 2273 if (element && focused_frame->Selection()
2275 .ComputeVisibleSelectionInDOMTreeDeprecated() 2274 .ComputeVisibleSelectionInDOMTreeDeprecated()
2276 .IsNone()) { 2275 .IsNone()) {
2277 // If the selection was cleared while the WebView was not 2276 // If the selection was cleared while the WebView was not
2278 // focused, then the focus element shows with a focus ring but 2277 // focused, then the focus element shows with a focus ring but
2279 // no caret and does respond to keyboard inputs. 2278 // no caret and does respond to keyboard inputs.
2280 focused_frame->GetDocument()->UpdateStyleAndLayoutTree(); 2279 focused_frame->GetDocument()->UpdateStyleAndLayoutTree();
2281 if (element->IsTextControl()) { 2280 if (element->IsTextControl()) {
2282 element->UpdateFocusAppearance(SelectionBehaviorOnFocus::kRestore); 2281 element->UpdateFocusAppearance(SelectionBehaviorOnFocus::kRestore);
2283 } else if (HasEditableStyle(*element)) { 2282 } else if (HasEditableStyle(*element)) {
2284 // updateFocusAppearance() selects all the text of 2283 // updateFocusAppearance() selects all the text of
2285 // contentseditable DIVs. So we set the selection explicitly 2284 // contentseditable DIVs. So we set the selection explicitly
2286 // instead. Note that this has the side effect of moving the 2285 // instead. Note that this has the side effect of moving the
2287 // caret back to the beginning of the text. 2286 // caret back to the beginning of the text.
2288 Position position(element, 0); 2287 Position position(element, 0);
2289 focused_frame->Selection().SetSelection( 2288 focused_frame->Selection().SetSelection(
2290 SelectionInDOMTree::Builder().Collapse(position).Build()); 2289 SelectionInDOMTree::Builder().Collapse(position).Build());
2291 } 2290 }
2292 } 2291 }
2292 // TODO(ekaramad): We need to figure out the right way to propagate page
2293 // focus to OOPIFs. Right now WebFrameWidgetImpl::SetFocus never gets
2294 // called (https://crbug.com/689777).
2295 WebLocalFrameBase::FromFrame(focused_frame->LocalFrameRoot())
2296 ->FrameWidget()
2297 ->ime_accept_events_ = true;
2293 } 2298 }
2294 ime_accept_events_ = true;
2295 } else { 2299 } else {
2296 HidePopups(); 2300 HidePopups();
2297 2301
2298 // Clear focus on the currently focused frame if any. 2302 // Clear focus on the currently focused frame if any.
2299 if (!page_) 2303 if (!page_ || !focused_frame)
2300 return; 2304 return;
2301 2305
2302 LocalFrame* frame = page_->MainFrame() && page_->MainFrame()->IsLocalFrame() 2306 // Finish an ongoing composition to delete the composition node.
2303 ? page_->DeprecatedLocalMainFrame() 2307 if (focused_frame->GetInputMethodController().HasComposition()) {
2304 : nullptr; 2308 // TODO(editing-dev): The use of
2305 if (!frame) 2309 // updateStyleAndLayoutIgnorePendingStylesheets needs to be audited.
2306 return; 2310 // See http://crbug.com/590369 for more details.
2311 focused_frame->GetDocument()
2312 ->UpdateStyleAndLayoutIgnorePendingStylesheets();
2307 2313
2308 LocalFrame* focused_frame = FocusedLocalFrameInWidget(); 2314 focused_frame->GetInputMethodController().FinishComposingText(
2309 if (focused_frame) { 2315 InputMethodController::kKeepSelection);
2310 // Finish an ongoing composition to delete the composition node.
2311 if (focused_frame->GetInputMethodController().HasComposition()) {
2312 // TODO(editing-dev): The use of
2313 // updateStyleAndLayoutIgnorePendingStylesheets needs to be audited.
2314 // See http://crbug.com/590369 for more details.
2315 focused_frame->GetDocument()
2316 ->UpdateStyleAndLayoutIgnorePendingStylesheets();
2317
2318 focused_frame->GetInputMethodController().FinishComposingText(
2319 InputMethodController::kKeepSelection);
2320 } 2316 }
2321 ime_accept_events_ = false; 2317 // TODO(ekaramad): We need to figure out the right way to propagate page
2322 } 2318 // focus to OOPIFs. Right now WebFrameWidgetImpl::SetFocus never gets
2319 // called (https://crbug.com/689777).
2320 WebLocalFrameBase::FromFrame(focused_frame->LocalFrameRoot())
2321 ->FrameWidget()
2322 ->ime_accept_events_ = false;
2323 } 2323 }
2324 } 2324 }
2325 2325
2326 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as 2326 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2327 // well. This code needs to be refactored (http://crbug.com/629721). 2327 // well. This code needs to be refactored (http://crbug.com/629721).
2328 WebRange WebViewImpl::CompositionRange() { 2328 WebRange WebViewImpl::CompositionRange() {
2329 LocalFrame* focused = FocusedLocalFrameAvailableForIme(); 2329 if (!MainFrameImpl() || !MainFrameImpl()->FrameWidget()->ime_accept_events_)
2330 return WebRange();
2331
2332 LocalFrame* focused = FocusedLocalFrameInWidget();
2330 if (!focused) 2333 if (!focused)
2331 return WebRange(); 2334 return WebRange();
2332 2335
2333 const EphemeralRange range = 2336 const EphemeralRange range =
2334 focused->GetInputMethodController().CompositionEphemeralRange(); 2337 focused->GetInputMethodController().CompositionEphemeralRange();
2335 if (range.IsNull()) 2338 if (range.IsNull())
2336 return WebRange(); 2339 return WebRange();
2337 2340
2338 Element* editable = 2341 Element* editable =
2339 focused->Selection().RootEditableElementOrDocumentElement(); 2342 focused->Selection().RootEditableElementOrDocumentElement();
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after
4106 // TODO(oshima): Investigate if this should return the ScreenInfo's scale 4109 // TODO(oshima): Investigate if this should return the ScreenInfo's scale
4107 // factor rather than page's scale factor, which can be 1 in use-zoom-for-dsf 4110 // factor rather than page's scale factor, which can be 1 in use-zoom-for-dsf
4108 // mode. 4111 // mode.
4109 if (!GetPage()) 4112 if (!GetPage())
4110 return 1; 4113 return 1;
4111 4114
4112 return GetPage()->DeviceScaleFactorDeprecated(); 4115 return GetPage()->DeviceScaleFactorDeprecated();
4113 } 4116 }
4114 4117
4115 LocalFrame* WebViewImpl::FocusedLocalFrameInWidget() const { 4118 LocalFrame* WebViewImpl::FocusedLocalFrameInWidget() const {
4116 if (!MainFrameImpl()) 4119 if (auto* frame = MainFrameImpl())
4117 return nullptr; 4120 return frame->FrameWidget()->FocusedLocalFrame();
4118 4121 return nullptr;
4119 LocalFrame* focused_frame = ToLocalFrame(FocusedCoreFrame());
4120 if (focused_frame->LocalFrameRoot() != MainFrameImpl()->GetFrame())
4121 return nullptr;
4122 return focused_frame;
4123 }
4124
4125 LocalFrame* WebViewImpl::FocusedLocalFrameAvailableForIme() const {
4126 return ime_accept_events_ ? FocusedLocalFrameInWidget() : nullptr;
4127 } 4122 }
4128 4123
4129 } // namespace blink 4124 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698