OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. |
8 * All rights reserved. | 8 * All rights reserved. |
9 * (C) 2007 Eric Seidel (eric@webkit.org) | 9 * (C) 2007 Eric Seidel (eric@webkit.org) |
10 * | 10 * |
(...skipping 2663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2674 // animations) is difficult, for now we match IE's heuristic and bring | 2674 // animations) is difficult, for now we match IE's heuristic and bring |
2675 // up the keyboard if there's been any gesture since load. | 2675 // up the keyboard if there's been any gesture since load. |
2676 document().page()->chromeClient().showVirtualKeyboardOnElementFocus(); | 2676 document().page()->chromeClient().showVirtualKeyboardOnElementFocus(); |
2677 } | 2677 } |
2678 } | 2678 } |
2679 | 2679 |
2680 void Element::updateFocusAppearance( | 2680 void Element::updateFocusAppearance( |
2681 SelectionBehaviorOnFocus selectionBehavior) { | 2681 SelectionBehaviorOnFocus selectionBehavior) { |
2682 if (selectionBehavior == SelectionBehaviorOnFocus::None) | 2682 if (selectionBehavior == SelectionBehaviorOnFocus::None) |
2683 return; | 2683 return; |
2684 | |
2685 LocalFrame* frame = document().frame(); | |
yosin_UTC9
2017/02/09 13:02:17
We can early return here if |!frame|.
Let's hoist
| |
2684 if (isRootEditableElement(*this)) { | 2686 if (isRootEditableElement(*this)) { |
2685 LocalFrame* frame = document().frame(); | |
2686 if (!frame) | 2687 if (!frame) |
2687 return; | 2688 return; |
2688 | 2689 |
2689 // When focusing an editable element in an iframe, don't reset the selection | 2690 // When focusing an editable element in an iframe, don't reset the selection |
2690 // if it already contains a selection. | 2691 // if it already contains a selection. |
2691 if (this == frame->selection().rootEditableElement()) | 2692 if (this == frame->selection().rootEditableElement()) |
2692 return; | 2693 return; |
2693 | 2694 |
2694 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 2695 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
2695 // needs to be audited. See http://crbug.com/590369 for more details. | 2696 // needs to be audited. See http://crbug.com/590369 for more details. |
2696 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 2697 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
2697 | 2698 |
2698 // FIXME: We should restore the previous selection if there is one. | 2699 // FIXME: We should restore the previous selection if there is one. |
2699 // Passing DoNotSetFocus as this function is called after | 2700 // Passing DoNotSetFocus as this function is called after |
2700 // FocusController::setFocusedElement() and we don't want to change the | 2701 // FocusController::setFocusedElement() and we don't want to change the |
2701 // focus to a new Element. | 2702 // focus to a new Element. |
2702 frame->selection().setSelection( | 2703 frame->selection().setSelection( |
2703 SelectionInDOMTree::Builder() | 2704 SelectionInDOMTree::Builder() |
2704 .collapse(firstPositionInOrBeforeNode(this)) | 2705 .collapse(firstPositionInOrBeforeNode(this)) |
2705 .build(), | 2706 .build(), |
2706 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 2707 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
2707 FrameSelection::DoNotSetFocus); | 2708 FrameSelection::DoNotSetFocus); |
2708 frame->selection().revealSelection(); | 2709 frame->selection().revealSelection(); |
2709 } else if (layoutObject() && !layoutObject()->isLayoutPart()) { | 2710 } else { |
2710 layoutObject()->scrollRectToVisible(boundingBox()); | 2711 // This element is non editable. |
2712 if (frame) | |
2713 frame->selection().clear(); | |
yosin_UTC9
2017/02/09 13:02:17
Focus and selection are individual identity. We do
hugoh_UTC2
2017/02/11 03:42:22
True, here we would clear() too often. Let's put t
| |
2714 | |
2715 if (layoutObject() && !layoutObject()->isLayoutPart()) | |
2716 layoutObject()->scrollRectToVisible(boundingBox()); | |
2711 } | 2717 } |
2712 } | 2718 } |
2713 | 2719 |
2714 void Element::blur() { | 2720 void Element::blur() { |
2715 cancelFocusAppearanceUpdate(); | 2721 cancelFocusAppearanceUpdate(); |
2716 if (adjustedFocusedElementInTreeScope() == this) { | 2722 if (adjustedFocusedElementInTreeScope() == this) { |
2717 Document& doc = document(); | 2723 Document& doc = document(); |
2718 if (doc.page()) | 2724 if (doc.page()) |
2719 doc.page()->focusController().setFocusedElement(0, doc.frame()); | 2725 doc.page()->focusController().setFocusedElement(0, doc.frame()); |
2720 else | 2726 else |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4134 } | 4140 } |
4135 | 4141 |
4136 DEFINE_TRACE_WRAPPERS(Element) { | 4142 DEFINE_TRACE_WRAPPERS(Element) { |
4137 if (hasRareData()) { | 4143 if (hasRareData()) { |
4138 visitor->traceWrappers(elementRareData()); | 4144 visitor->traceWrappers(elementRareData()); |
4139 } | 4145 } |
4140 ContainerNode::traceWrappers(visitor); | 4146 ContainerNode::traceWrappers(visitor); |
4141 } | 4147 } |
4142 | 4148 |
4143 } // namespace blink | 4149 } // namespace blink |
OLD | NEW |