Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "core/editing/PositionWithAffinity.h" | 31 #include "core/editing/PositionWithAffinity.h" |
| 32 #include "platform/Timer.h" | 32 #include "platform/Timer.h" |
| 33 #include "platform/geometry/LayoutRect.h" | 33 #include "platform/geometry/LayoutRect.h" |
| 34 #include "platform/heap/GarbageCollected.h" | 34 #include "platform/heap/GarbageCollected.h" |
| 35 #include "platform/heap/Member.h" | 35 #include "platform/heap/Member.h" |
| 36 #include <memory> | 36 #include <memory> |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class CaretDisplayItemClient; | 40 class CaretDisplayItemClient; |
| 41 class CharacterData; | |
| 42 class DisplayItemClient; | 41 class DisplayItemClient; |
| 43 class Document; | 42 class Document; |
| 44 class GraphicsContext; | 43 class GraphicsContext; |
| 45 class Node; | 44 class LayoutBlock; |
| 46 class LocalFrame; | 45 class LocalFrame; |
| 47 class SelectionEditor; | 46 class SelectionEditor; |
| 48 | 47 |
| 49 enum class CaretVisibility { Visible, Hidden }; | 48 enum class CaretVisibility { Visible, Hidden }; |
| 50 | 49 |
| 51 class CORE_EXPORT FrameCaret final | 50 class CORE_EXPORT FrameCaret final |
| 52 : public GarbageCollectedFinalized<FrameCaret>, | 51 : public GarbageCollectedFinalized<FrameCaret>, |
| 53 public SynchronousMutationObserver { | 52 public SynchronousMutationObserver { |
| 54 USING_GARBAGE_COLLECTED_MIXIN(FrameCaret); | 53 USING_GARBAGE_COLLECTED_MIXIN(FrameCaret); |
| 55 | 54 |
| 56 public: | 55 public: |
| 57 FrameCaret(LocalFrame&, const SelectionEditor&); | 56 FrameCaret(LocalFrame&, const SelectionEditor&); |
| 58 ~FrameCaret(); | 57 ~FrameCaret(); |
| 59 | 58 |
| 60 const DisplayItemClient& displayItemClient() const; | 59 void setVisualRect(const LayoutRect&); |
| 60 const DisplayItemClient& getDisplayItemClient() const; | |
| 61 | |
| 61 bool isActive() const { return caretPosition().isNotNull(); } | 62 bool isActive() const { return caretPosition().isNotNull(); } |
| 62 | 63 |
| 63 void documentAttached(Document*); | 64 void documentAttached(Document*); |
| 64 void updateAppearance(); | 65 void updateAppearance(); |
| 65 | 66 |
| 66 // Used to suspend caret blinking while the mouse is down. | 67 // Used to suspend caret blinking while the mouse is down. |
| 67 void setCaretBlinkingSuspended(bool suspended) { | 68 void setCaretBlinkingSuspended(bool suspended) { |
| 68 m_isCaretBlinkingSuspended = suspended; | 69 m_isCaretBlinkingSuspended = suspended; |
| 69 } | 70 } |
| 70 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; } | 71 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; } |
| 71 void stopCaretBlinkTimer(); | 72 void stopCaretBlinkTimer(); |
| 72 void startBlinkCaret(); | 73 void startBlinkCaret(); |
| 74 void setCaretVisibility(CaretVisibility); | |
| 75 IntRect absoluteCaretBounds() const; | |
| 73 | 76 |
| 74 void setCaretVisibility(CaretVisibility); | 77 // Return the caret rect in local coordinate space of |caretLayoutBlock|. |
|
wkorman
2017/01/31 20:40:28
Suggest adding to comment to define rect more expl
| |
| 75 void setCaretRectNeedsUpdate(); | 78 LayoutRect caretLocalRect() const; |
| 76 // If |forceInvalidation| is true the caret's previous and new rectangles | 79 LayoutBlock* caretLayoutBlock() const; |
| 77 // are forcibly invalidated regardless of the state of the blink timer. | 80 |
| 78 void invalidateCaretRect(bool forceInvalidation); | 81 void setMayNeedPaintInvalidation(); |
| 79 IntRect absoluteCaretBounds() const; | 82 void setNeedsPaintInvalidation(); |
| 80 | 83 |
| 81 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; } | 84 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; } |
| 82 void setShouldShowBlockCursor(bool); | 85 void setShouldShowBlockCursor(bool); |
| 83 | 86 |
| 84 void paintCaret(GraphicsContext&, const LayoutPoint&); | 87 void paintCaret(GraphicsContext&, const LayoutPoint&); |
| 85 | 88 |
| 86 void dataWillChange(const CharacterData&); | |
| 87 | |
| 88 // For unittests | 89 // For unittests |
| 89 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } | 90 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } |
| 90 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; } | |
| 91 | 91 |
| 92 DECLARE_TRACE(); | 92 DECLARE_TRACE(); |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 friend class FrameSelectionTest; | 95 friend class FrameSelectionTest; |
| 96 | 96 |
| 97 const PositionWithAffinity caretPosition() const; | 97 const PositionWithAffinity caretPosition() const; |
| 98 | 98 |
| 99 bool shouldBlinkCaret() const; | 99 bool shouldBlinkCaret() const; |
| 100 void caretBlinkTimerFired(TimerBase*); | 100 void caretBlinkTimerFired(TimerBase*); |
| 101 bool caretPositionIsValidForDocument(const Document&) const; | 101 bool caretPositionIsValidForDocument(const Document&) const; |
| 102 | 102 |
| 103 // Implementation of |SynchronousMutationObserver| member functions. | 103 // Implementation of |SynchronousMutationObserver| member functions. |
| 104 void contextDestroyed(Document*) final; | 104 void contextDestroyed(Document*) final; |
|
yosin_UTC9
2017/01/31 20:12:58
Since FrameCaret doesn't hold |Node| anymore, Fram
Xianzhu
2017/02/02 23:42:06
Great. Done.
| |
| 105 void nodeWillBeRemoved(Node&) final; | 105 |
| 106 void scheduleVisualUpdate(); | |
| 106 | 107 |
| 107 const Member<const SelectionEditor> m_selectionEditor; | 108 const Member<const SelectionEditor> m_selectionEditor; |
| 108 const Member<LocalFrame> m_frame; | 109 const Member<LocalFrame> m_frame; |
| 109 const std::unique_ptr<CaretDisplayItemClient> m_caretBase; | 110 const std::unique_ptr<CaretDisplayItemClient> m_caretBase; |
| 110 // The last node which painted the caret. Retained for clearing the old | |
| 111 // caret when it moves. | |
| 112 Member<Node> m_previousCaretNode; | |
| 113 Member<Node> m_previousCaretAnchorNode; | |
| 114 LayoutRect m_previousCaretRect; | |
| 115 CaretVisibility m_caretVisibility; | 111 CaretVisibility m_caretVisibility; |
| 116 CaretVisibility m_previousCaretVisibility; | |
| 117 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. | 112 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. |
| 118 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; | 113 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; |
| 119 bool m_caretRectDirty : 1; | |
| 120 bool m_shouldPaintCaret : 1; | 114 bool m_shouldPaintCaret : 1; |
| 121 bool m_isCaretBlinkingSuspended : 1; | 115 bool m_isCaretBlinkingSuspended : 1; |
| 122 bool m_shouldShowBlockCursor : 1; | 116 bool m_shouldShowBlockCursor : 1; |
| 123 | 117 |
| 124 DISALLOW_COPY_AND_ASSIGN(FrameCaret); | 118 DISALLOW_COPY_AND_ASSIGN(FrameCaret); |
| 125 }; | 119 }; |
| 126 | 120 |
| 127 } // namespace blink | 121 } // namespace blink |
| 128 | 122 |
| 129 #endif // FrameCaret_h | 123 #endif // FrameCaret_h |
| OLD | NEW |