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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameWidgetImpl.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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 layer_tree_view_(nullptr), 111 layer_tree_view_(nullptr),
112 root_layer_(nullptr), 112 root_layer_(nullptr),
113 root_graphics_layer_(nullptr), 113 root_graphics_layer_(nullptr),
114 is_accelerated_compositing_active_(false), 114 is_accelerated_compositing_active_(false),
115 layer_tree_view_closed_(false), 115 layer_tree_view_closed_(false),
116 suppress_next_keypress_event_(false), 116 suppress_next_keypress_event_(false),
117 background_color_override_enabled_(false), 117 background_color_override_enabled_(false),
118 background_color_override_(Color::kTransparent), 118 background_color_override_(Color::kTransparent),
119 base_background_color_override_enabled_(false), 119 base_background_color_override_enabled_(false),
120 base_background_color_override_(Color::kTransparent), 120 base_background_color_override_(Color::kTransparent),
121 ime_accept_events_(true),
122 self_keep_alive_(this) { 121 self_keep_alive_(this) {
123 DCHECK(local_root_->GetFrame()->IsLocalRoot()); 122 DCHECK(local_root_->GetFrame()->IsLocalRoot());
124 InitializeLayerTreeView(); 123 InitializeLayerTreeView();
125 local_root_->SetFrameWidget(this); 124 local_root_->SetFrameWidget(this);
126 125
127 if (local_root->Parent()) 126 if (local_root->Parent())
128 SetBackgroundColorOverride(Color::kTransparent); 127 SetBackgroundColorOverride(Color::kTransparent);
129 } 128 }
130 129
131 WebFrameWidgetImpl::~WebFrameWidgetImpl() {} 130 WebFrameWidgetImpl::~WebFrameWidgetImpl() {}
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 UpdateBaseBackgroundColor(); 453 UpdateBaseBackgroundColor();
455 } 454 }
456 455
457 void WebFrameWidgetImpl::UpdateBaseBackgroundColor() { 456 void WebFrameWidgetImpl::UpdateBaseBackgroundColor() {
458 local_root_->GetFrameView()->SetBaseBackgroundColor(BaseBackgroundColor()); 457 local_root_->GetFrameView()->SetBaseBackgroundColor(BaseBackgroundColor());
459 } 458 }
460 459
461 WebInputMethodController* 460 WebInputMethodController*
462 WebFrameWidgetImpl::GetActiveWebInputMethodController() const { 461 WebFrameWidgetImpl::GetActiveWebInputMethodController() const {
463 WebLocalFrameBase* local_frame = 462 WebLocalFrameBase* local_frame =
464 WebLocalFrameBase::FromFrame(FocusedLocalFrameInWidget()); 463 WebLocalFrameBase::FromFrame(FocusedLocalFrame());
465 return local_frame ? local_frame->GetInputMethodController() : nullptr; 464 return local_frame ? local_frame->GetInputMethodController() : nullptr;
466 } 465 }
467 466
468 void WebFrameWidgetImpl::ScheduleAnimation() { 467 void WebFrameWidgetImpl::ScheduleAnimation() {
469 if (layer_tree_view_) { 468 if (layer_tree_view_) {
470 layer_tree_view_->SetNeedsBeginFrame(); 469 layer_tree_view_->SetNeedsBeginFrame();
471 return; 470 return;
472 } 471 }
473 DCHECK(client_); 472 DCHECK(client_);
474 client_->ScheduleAnimation(); 473 client_->ScheduleAnimation();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 // instead. Note that this has the side effect of moving the 530 // instead. Note that this has the side effect of moving the
532 // caret back to the beginning of the text. 531 // caret back to the beginning of the text.
533 Position position(element, 0); 532 Position position(element, 0);
534 focused_frame->Selection().SetSelection( 533 focused_frame->Selection().SetSelection(
535 SelectionInDOMTree::Builder().Collapse(position).Build()); 534 SelectionInDOMTree::Builder().Collapse(position).Build());
536 } 535 }
537 } 536 }
538 } 537 }
539 ime_accept_events_ = true; 538 ime_accept_events_ = true;
540 } else { 539 } else {
541 LocalFrame* focused_frame = FocusedLocalFrameInWidget(); 540 LocalFrame* focused_frame = FocusedLocalFrame();
542 if (focused_frame) { 541 if (focused_frame) {
543 // Finish an ongoing composition to delete the composition node. 542 // Finish an ongoing composition to delete the composition node.
544 if (focused_frame->GetInputMethodController().HasComposition()) { 543 if (focused_frame->GetInputMethodController().HasComposition()) {
545 // TODO(editing-dev): The use of 544 // TODO(editing-dev): The use of
546 // updateStyleAndLayoutIgnorePendingStylesheets needs to be audited. 545 // updateStyleAndLayoutIgnorePendingStylesheets needs to be audited.
547 // See http://crbug.com/590369 for more details. 546 // See http://crbug.com/590369 for more details.
548 focused_frame->GetDocument() 547 focused_frame->GetDocument()
549 ->UpdateStyleAndLayoutIgnorePendingStylesheets(); 548 ->UpdateStyleAndLayoutIgnorePendingStylesheets();
550 549
551 focused_frame->GetInputMethodController().FinishComposingText( 550 focused_frame->GetInputMethodController().FinishComposingText(
552 InputMethodController::kKeepSelection); 551 InputMethodController::kKeepSelection);
553 } 552 }
554 ime_accept_events_ = false; 553 ime_accept_events_ = false;
555 } 554 }
556 } 555 }
557 } 556 }
558 557
559 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 558 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
560 // code needs to be refactored (http://crbug.com/629721). 559 // code needs to be refactored (http://crbug.com/629721).
561 WebRange WebFrameWidgetImpl::CompositionRange() { 560 WebRange WebFrameWidgetImpl::CompositionRange() {
562 LocalFrame* focused = FocusedLocalFrameAvailableForIme(); 561 if (!ime_accept_events_)
562 return WebRange();
563
564 LocalFrame* focused = FocusedLocalFrame();
563 if (!focused) 565 if (!focused)
564 return WebRange(); 566 return WebRange();
565 567
566 const EphemeralRange range = 568 const EphemeralRange range =
567 focused->GetInputMethodController().CompositionEphemeralRange(); 569 focused->GetInputMethodController().CompositionEphemeralRange();
568 if (range.IsNull()) 570 if (range.IsNull())
569 return WebRange(); 571 return WebRange();
570 572
571 Element* editable = 573 Element* editable =
572 focused->Selection().RootEditableElementOrDocumentElement(); 574 focused->Selection().RootEditableElementOrDocumentElement();
(...skipping 12 matching lines...) Expand all
585 if (!local_root_->GetFrameView()) 587 if (!local_root_->GetFrameView())
586 return base_background_color_; 588 return base_background_color_;
587 LocalFrameView* view = local_root_->GetFrameView(); 589 LocalFrameView* view = local_root_->GetFrameView();
588 return view->DocumentBackgroundColor().Rgb(); 590 return view->DocumentBackgroundColor().Rgb();
589 } 591 }
590 592
591 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 593 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
592 // code needs to be refactored (http://crbug.com/629721). 594 // code needs to be refactored (http://crbug.com/629721).
593 bool WebFrameWidgetImpl::SelectionBounds(WebRect& anchor, 595 bool WebFrameWidgetImpl::SelectionBounds(WebRect& anchor,
594 WebRect& focus) const { 596 WebRect& focus) const {
595 const LocalFrame* local_frame = FocusedLocalFrameInWidget(); 597 const LocalFrame* local_frame = FocusedLocalFrame();
596 if (!local_frame) 598 if (!local_frame)
597 return false; 599 return false;
598 600
599 FrameSelection& selection = local_frame->Selection(); 601 FrameSelection& selection = local_frame->Selection();
600 if (!selection.IsAvailable() || selection.GetSelectionInDOMTree().IsNone()) 602 if (!selection.IsAvailable() || selection.GetSelectionInDOMTree().IsNone())
601 return false; 603 return false;
602 604
603 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 605 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
604 // needs to be audited. See http://crbug.com/590369 for more details. 606 // needs to be audited. See http://crbug.com/590369 for more details.
605 local_frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 607 local_frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
(...skipping 28 matching lines...) Expand all
634 636
635 if (!selection.ComputeVisibleSelectionInDOMTree().IsBaseFirst()) 637 if (!selection.ComputeVisibleSelectionInDOMTree().IsBaseFirst())
636 std::swap(anchor, focus); 638 std::swap(anchor, focus);
637 return true; 639 return true;
638 } 640 }
639 641
640 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 642 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
641 // code needs to be refactored (http://crbug.com/629721). 643 // code needs to be refactored (http://crbug.com/629721).
642 bool WebFrameWidgetImpl::SelectionTextDirection(WebTextDirection& start, 644 bool WebFrameWidgetImpl::SelectionTextDirection(WebTextDirection& start,
643 WebTextDirection& end) const { 645 WebTextDirection& end) const {
644 const LocalFrame* frame = FocusedLocalFrameInWidget(); 646 const LocalFrame* frame = FocusedLocalFrame();
645 if (!frame) 647 if (!frame)
646 return false; 648 return false;
647 649
648 FrameSelection& selection = frame->Selection(); 650 FrameSelection& selection = frame->Selection();
649 if (!selection.IsAvailable()) 651 if (!selection.IsAvailable())
650 return false; 652 return false;
651 653
652 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 654 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
653 // needs to be audited. See http://crbug.com/590369 for more details. 655 // needs to be audited. See http://crbug.com/590369 for more details.
654 frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 656 frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
655 657
656 if (selection.ComputeVisibleSelectionInDOMTree() 658 if (selection.ComputeVisibleSelectionInDOMTree()
657 .ToNormalizedEphemeralRange() 659 .ToNormalizedEphemeralRange()
658 .IsNull()) 660 .IsNull())
659 return false; 661 return false;
660 start = ToWebTextDirection(PrimaryDirectionOf( 662 start = ToWebTextDirection(PrimaryDirectionOf(
661 *selection.ComputeVisibleSelectionInDOMTree().Start().AnchorNode())); 663 *selection.ComputeVisibleSelectionInDOMTree().Start().AnchorNode()));
662 end = ToWebTextDirection(PrimaryDirectionOf( 664 end = ToWebTextDirection(PrimaryDirectionOf(
663 *selection.ComputeVisibleSelectionInDOMTree().End().AnchorNode())); 665 *selection.ComputeVisibleSelectionInDOMTree().End().AnchorNode()));
664 return true; 666 return true;
665 } 667 }
666 668
667 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 669 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
668 // code needs to be refactored (http://crbug.com/629721). 670 // code needs to be refactored (http://crbug.com/629721).
669 bool WebFrameWidgetImpl::IsSelectionAnchorFirst() const { 671 bool WebFrameWidgetImpl::IsSelectionAnchorFirst() const {
670 if (const LocalFrame* frame = FocusedLocalFrameInWidget()) { 672 if (const LocalFrame* frame = FocusedLocalFrame()) {
671 FrameSelection& selection = frame->Selection(); 673 FrameSelection& selection = frame->Selection();
672 return selection.IsAvailable() && 674 return selection.IsAvailable() &&
673 selection.ComputeVisibleSelectionInDOMTreeDeprecated().IsBaseFirst(); 675 selection.ComputeVisibleSelectionInDOMTreeDeprecated().IsBaseFirst();
674 } 676 }
675 return false; 677 return false;
676 } 678 }
677 679
678 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 680 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
679 // code needs to be refactored (http://crbug.com/629721). 681 // code needs to be refactored (http://crbug.com/629721).
680 WebRange WebFrameWidgetImpl::CaretOrSelectionRange() { 682 WebRange WebFrameWidgetImpl::CaretOrSelectionRange() {
681 LocalFrame* focused = FocusedLocalFrameInWidget(); 683 LocalFrame* focused = FocusedLocalFrame();
682 if (!focused) 684 if (!focused)
683 return WebRange(); 685 return WebRange();
684 686
685 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 687 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
686 // needs to be audited. See http://crbug.com/590369 for more details. 688 // needs to be audited. See http://crbug.com/590369 for more details.
687 focused->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 689 focused->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
688 690
689 return focused->GetInputMethodController().GetSelectionOffsets(); 691 return focused->GetInputMethodController().GetSelectionOffsets();
690 } 692 }
691 693
692 void WebFrameWidgetImpl::SetTextDirection(WebTextDirection direction) { 694 void WebFrameWidgetImpl::SetTextDirection(WebTextDirection direction) {
693 // The Editor::setBaseWritingDirection() function checks if we can change 695 // The Editor::setBaseWritingDirection() function checks if we can change
694 // the text direction of the selected node and updates its DOM "dir" 696 // the text direction of the selected node and updates its DOM "dir"
695 // attribute and its CSS "direction" property. 697 // attribute and its CSS "direction" property.
696 // So, we just call the function as Safari does. 698 // So, we just call the function as Safari does.
697 const LocalFrame* focused = FocusedLocalFrameInWidget(); 699 const LocalFrame* focused = FocusedLocalFrame();
698 if (!focused) 700 if (!focused)
699 return; 701 return;
700 702
701 Editor& editor = focused->GetEditor(); 703 Editor& editor = focused->GetEditor();
702 if (!editor.CanEdit()) 704 if (!editor.CanEdit())
703 return; 705 return;
704 706
705 switch (direction) { 707 switch (direction) {
706 case kWebTextDirectionDefault: 708 case kWebTextDirectionDefault:
707 editor.SetBaseWritingDirection(NaturalWritingDirection); 709 editor.SetBaseWritingDirection(NaturalWritingDirection);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 741 }
740 742
741 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This 743 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This
742 // code needs to be refactored (http://crbug.com/629721). 744 // code needs to be refactored (http://crbug.com/629721).
743 bool WebFrameWidgetImpl::GetCompositionCharacterBounds( 745 bool WebFrameWidgetImpl::GetCompositionCharacterBounds(
744 WebVector<WebRect>& bounds) { 746 WebVector<WebRect>& bounds) {
745 WebRange range = CompositionRange(); 747 WebRange range = CompositionRange();
746 if (range.IsEmpty()) 748 if (range.IsEmpty())
747 return false; 749 return false;
748 750
749 LocalFrame* frame = FocusedLocalFrameInWidget(); 751 LocalFrame* frame = FocusedLocalFrame();
750 if (!frame) 752 if (!frame)
751 return false; 753 return false;
752 754
753 WebLocalFrameBase* web_local_frame = WebLocalFrameBase::FromFrame(frame); 755 WebLocalFrameBase* web_local_frame = WebLocalFrameBase::FromFrame(frame);
754 size_t character_count = range.length(); 756 size_t character_count = range.length();
755 size_t offset = range.StartOffset(); 757 size_t offset = range.StartOffset();
756 WebVector<WebRect> result(character_count); 758 WebVector<WebRect> result(character_count);
757 WebRect webrect; 759 WebRect webrect;
758 for (size_t i = 0; i < character_count; ++i) { 760 for (size_t i = 0; i < character_count; ++i) {
759 if (!web_local_frame->FirstRectForCharacterRange(offset + i, 1, webrect)) { 761 if (!web_local_frame->FirstRectForCharacterRange(offset + i, 1, webrect)) {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 const IntPoint& pos_in_root_frame) { 1188 const IntPoint& pos_in_root_frame) {
1187 IntPoint doc_point( 1189 IntPoint doc_point(
1188 local_root_->GetFrame()->View()->RootFrameToContents(pos_in_root_frame)); 1190 local_root_->GetFrame()->View()->RootFrameToContents(pos_in_root_frame));
1189 HitTestResult result = 1191 HitTestResult result =
1190 local_root_->GetFrame()->GetEventHandler().HitTestResultAtPoint( 1192 local_root_->GetFrame()->GetEventHandler().HitTestResultAtPoint(
1191 doc_point, HitTestRequest::kReadOnly | HitTestRequest::kActive); 1193 doc_point, HitTestRequest::kReadOnly | HitTestRequest::kActive);
1192 result.SetToShadowHostIfInRestrictedShadowRoot(); 1194 result.SetToShadowHostIfInRestrictedShadowRoot();
1193 return result; 1195 return result;
1194 } 1196 }
1195 1197
1196 LocalFrame* WebFrameWidgetImpl::FocusedLocalFrameInWidget() const {
1197 LocalFrame* frame = GetPage()->GetFocusController().FocusedFrame();
1198 return (frame && frame->LocalFrameRoot() == local_root_->GetFrame())
1199 ? frame
1200 : nullptr;
1201 }
1202
1203 LocalFrame* WebFrameWidgetImpl::FocusedLocalFrameAvailableForIme() const {
1204 if (!ime_accept_events_)
1205 return nullptr;
1206 return FocusedLocalFrameInWidget();
1207 }
1208
1209 } // namespace blink 1198 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebFrameWidgetImpl.h ('k') | third_party/WebKit/Source/web/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698