OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 601 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
600 // needs to be audited. See http://crbug.com/590369 for more details. | 602 // needs to be audited. See http://crbug.com/590369 for more details. |
601 local_frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 603 local_frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
602 | 604 |
603 DocumentLifecycle::DisallowTransitionScope disallow_transition( | 605 DocumentLifecycle::DisallowTransitionScope disallow_transition( |
604 local_frame->GetDocument()->Lifecycle()); | 606 local_frame->GetDocument()->Lifecycle()); |
605 | 607 |
(...skipping 25 matching lines...) Expand all Loading... |
631 | 633 |
632 if (!selection.ComputeVisibleSelectionInDOMTree().IsBaseFirst()) | 634 if (!selection.ComputeVisibleSelectionInDOMTree().IsBaseFirst()) |
633 std::swap(anchor, focus); | 635 std::swap(anchor, focus); |
634 return true; | 636 return true; |
635 } | 637 } |
636 | 638 |
637 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 639 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
638 // code needs to be refactored (http://crbug.com/629721). | 640 // code needs to be refactored (http://crbug.com/629721). |
639 bool WebFrameWidgetImpl::SelectionTextDirection(WebTextDirection& start, | 641 bool WebFrameWidgetImpl::SelectionTextDirection(WebTextDirection& start, |
640 WebTextDirection& end) const { | 642 WebTextDirection& end) const { |
641 const LocalFrame* frame = FocusedLocalFrameInWidget(); | 643 const LocalFrame* frame = FocusedLocalFrame(); |
642 if (!frame) | 644 if (!frame) |
643 return false; | 645 return false; |
644 | 646 |
645 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 647 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
646 // needs to be audited. See http://crbug.com/590369 for more details. | 648 // needs to be audited. See http://crbug.com/590369 for more details. |
647 frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 649 frame->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
648 | 650 |
649 FrameSelection& selection = frame->Selection(); | 651 FrameSelection& selection = frame->Selection(); |
650 if (selection.ComputeVisibleSelectionInDOMTree() | 652 if (selection.ComputeVisibleSelectionInDOMTree() |
651 .ToNormalizedEphemeralRange() | 653 .ToNormalizedEphemeralRange() |
652 .IsNull()) | 654 .IsNull()) |
653 return false; | 655 return false; |
654 start = ToWebTextDirection(PrimaryDirectionOf( | 656 start = ToWebTextDirection(PrimaryDirectionOf( |
655 *selection.ComputeVisibleSelectionInDOMTree().Start().AnchorNode())); | 657 *selection.ComputeVisibleSelectionInDOMTree().Start().AnchorNode())); |
656 end = ToWebTextDirection(PrimaryDirectionOf( | 658 end = ToWebTextDirection(PrimaryDirectionOf( |
657 *selection.ComputeVisibleSelectionInDOMTree().end().AnchorNode())); | 659 *selection.ComputeVisibleSelectionInDOMTree().end().AnchorNode())); |
658 return true; | 660 return true; |
659 } | 661 } |
660 | 662 |
661 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 663 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
662 // code needs to be refactored (http://crbug.com/629721). | 664 // code needs to be refactored (http://crbug.com/629721). |
663 bool WebFrameWidgetImpl::IsSelectionAnchorFirst() const { | 665 bool WebFrameWidgetImpl::IsSelectionAnchorFirst() const { |
664 if (const LocalFrame* frame = FocusedLocalFrameInWidget()) { | 666 if (const LocalFrame* frame = FocusedLocalFrame()) { |
665 return frame->Selection() | 667 return frame->Selection() |
666 .ComputeVisibleSelectionInDOMTreeDeprecated() | 668 .ComputeVisibleSelectionInDOMTreeDeprecated() |
667 .IsBaseFirst(); | 669 .IsBaseFirst(); |
668 } | 670 } |
669 return false; | 671 return false; |
670 } | 672 } |
671 | 673 |
672 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 674 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
673 // code needs to be refactored (http://crbug.com/629721). | 675 // code needs to be refactored (http://crbug.com/629721). |
674 WebRange WebFrameWidgetImpl::CaretOrSelectionRange() { | 676 WebRange WebFrameWidgetImpl::CaretOrSelectionRange() { |
675 LocalFrame* focused = FocusedLocalFrameInWidget(); | 677 LocalFrame* focused = FocusedLocalFrame(); |
676 if (!focused) | 678 if (!focused) |
677 return WebRange(); | 679 return WebRange(); |
678 | 680 |
679 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 681 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
680 // needs to be audited. See http://crbug.com/590369 for more details. | 682 // needs to be audited. See http://crbug.com/590369 for more details. |
681 focused->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 683 focused->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
682 | 684 |
683 return focused->GetInputMethodController().GetSelectionOffsets(); | 685 return focused->GetInputMethodController().GetSelectionOffsets(); |
684 } | 686 } |
685 | 687 |
686 void WebFrameWidgetImpl::SetTextDirection(WebTextDirection direction) { | 688 void WebFrameWidgetImpl::SetTextDirection(WebTextDirection direction) { |
687 // The Editor::setBaseWritingDirection() function checks if we can change | 689 // The Editor::setBaseWritingDirection() function checks if we can change |
688 // the text direction of the selected node and updates its DOM "dir" | 690 // the text direction of the selected node and updates its DOM "dir" |
689 // attribute and its CSS "direction" property. | 691 // attribute and its CSS "direction" property. |
690 // So, we just call the function as Safari does. | 692 // So, we just call the function as Safari does. |
691 const LocalFrame* focused = FocusedLocalFrameInWidget(); | 693 const LocalFrame* focused = FocusedLocalFrame(); |
692 if (!focused) | 694 if (!focused) |
693 return; | 695 return; |
694 | 696 |
695 Editor& editor = focused->GetEditor(); | 697 Editor& editor = focused->GetEditor(); |
696 if (!editor.CanEdit()) | 698 if (!editor.CanEdit()) |
697 return; | 699 return; |
698 | 700 |
699 switch (direction) { | 701 switch (direction) { |
700 case kWebTextDirectionDefault: | 702 case kWebTextDirectionDefault: |
701 editor.SetBaseWritingDirection(NaturalWritingDirection); | 703 editor.SetBaseWritingDirection(NaturalWritingDirection); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 735 } |
734 | 736 |
735 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 737 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
736 // code needs to be refactored (http://crbug.com/629721). | 738 // code needs to be refactored (http://crbug.com/629721). |
737 bool WebFrameWidgetImpl::GetCompositionCharacterBounds( | 739 bool WebFrameWidgetImpl::GetCompositionCharacterBounds( |
738 WebVector<WebRect>& bounds) { | 740 WebVector<WebRect>& bounds) { |
739 WebRange range = CompositionRange(); | 741 WebRange range = CompositionRange(); |
740 if (range.IsEmpty()) | 742 if (range.IsEmpty()) |
741 return false; | 743 return false; |
742 | 744 |
743 LocalFrame* frame = FocusedLocalFrameInWidget(); | 745 LocalFrame* frame = FocusedLocalFrame(); |
744 if (!frame) | 746 if (!frame) |
745 return false; | 747 return false; |
746 | 748 |
747 WebLocalFrameBase* web_local_frame = WebLocalFrameBase::FromFrame(frame); | 749 WebLocalFrameBase* web_local_frame = WebLocalFrameBase::FromFrame(frame); |
748 size_t character_count = range.length(); | 750 size_t character_count = range.length(); |
749 size_t offset = range.StartOffset(); | 751 size_t offset = range.StartOffset(); |
750 WebVector<WebRect> result(character_count); | 752 WebVector<WebRect> result(character_count); |
751 WebRect webrect; | 753 WebRect webrect; |
752 for (size_t i = 0; i < character_count; ++i) { | 754 for (size_t i = 0; i < character_count; ++i) { |
753 if (!web_local_frame->FirstRectForCharacterRange(offset + i, 1, webrect)) { | 755 if (!web_local_frame->FirstRectForCharacterRange(offset + i, 1, webrect)) { |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 const IntPoint& pos_in_root_frame) { | 1183 const IntPoint& pos_in_root_frame) { |
1182 IntPoint doc_point( | 1184 IntPoint doc_point( |
1183 local_root_->GetFrame()->View()->RootFrameToContents(pos_in_root_frame)); | 1185 local_root_->GetFrame()->View()->RootFrameToContents(pos_in_root_frame)); |
1184 HitTestResult result = | 1186 HitTestResult result = |
1185 local_root_->GetFrame()->GetEventHandler().HitTestResultAtPoint( | 1187 local_root_->GetFrame()->GetEventHandler().HitTestResultAtPoint( |
1186 doc_point, HitTestRequest::kReadOnly | HitTestRequest::kActive); | 1188 doc_point, HitTestRequest::kReadOnly | HitTestRequest::kActive); |
1187 result.SetToShadowHostIfInRestrictedShadowRoot(); | 1189 result.SetToShadowHostIfInRestrictedShadowRoot(); |
1188 return result; | 1190 return result; |
1189 } | 1191 } |
1190 | 1192 |
1191 LocalFrame* WebFrameWidgetImpl::FocusedLocalFrameInWidget() const { | |
1192 LocalFrame* frame = GetPage()->GetFocusController().FocusedFrame(); | |
1193 return (frame && frame->LocalFrameRoot() == local_root_->GetFrame()) | |
1194 ? frame | |
1195 : nullptr; | |
1196 } | |
1197 | |
1198 LocalFrame* WebFrameWidgetImpl::FocusedLocalFrameAvailableForIme() const { | |
1199 if (!ime_accept_events_) | |
1200 return nullptr; | |
1201 return FocusedLocalFrameInWidget(); | |
1202 } | |
1203 | |
1204 } // namespace blink | 1193 } // namespace blink |
OLD | NEW |