Allow <attachment> elements to be focused
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 22:23:53 +0000 (22:23 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 22:23:53 +0000 (22:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141847

Reviewed by Enrica Casucci.

* css/html.css:
(attachment:focus):
Disable focus rings for <attachment>.

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::setFocus):
* html/HTMLAttachmentElement.h:
Allow HTMLAttachmentElement to get editing focus.
Let RenderAttachment know when focus changes.

* rendering/RenderAttachment.cpp:
(WebCore::RenderAttachment::paintReplaced):
Paint the background in cyan when we are inside the selection or have focus.
Otherwise, it will be gray.

(WebCore::RenderAttachment::focusChanged):
When focus changes, repaint.

* rendering/RenderAttachment.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180454 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/html.css
Source/WebCore/html/HTMLAttachmentElement.cpp
Source/WebCore/html/HTMLAttachmentElement.h
Source/WebCore/rendering/RenderAttachment.cpp
Source/WebCore/rendering/RenderAttachment.h

index 862ef57..f5c9459 100644 (file)
@@ -1,3 +1,30 @@
+2015-02-20  Tim Horton  <timothy_horton@apple.com>
+
+        Allow <attachment> elements to be focused
+        https://bugs.webkit.org/show_bug.cgi?id=141847
+
+        Reviewed by Enrica Casucci.
+
+        * css/html.css:
+        (attachment:focus):
+        Disable focus rings for <attachment>.
+
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::HTMLAttachmentElement::setFocus):
+        * html/HTMLAttachmentElement.h:
+        Allow HTMLAttachmentElement to get editing focus.
+        Let RenderAttachment know when focus changes.
+
+        * rendering/RenderAttachment.cpp:
+        (WebCore::RenderAttachment::paintReplaced):
+        Paint the background in cyan when we are inside the selection or have focus.
+        Otherwise, it will be gray.
+
+        (WebCore::RenderAttachment::focusChanged):
+        When focus changes, repaint.
+
+        * rendering/RenderAttachment.h:
+
 2015-02-20  Brent Fulgham  <bfulgham@apple.com>
 
         Rename ScrollElasticityController to ScrollController
index 1c831ef..638c6e0 100644 (file)
@@ -1184,6 +1184,12 @@ applet, embed, object, img {
 }
 #endif
 
+#if defined(ENABLE_ATTACHMENT_ELEMENT) && ENABLE_ATTACHMENT_ELEMENT
+attachment:focus {
+    outline: none;
+}
+#endif
+
 /* page */
 
 @page {
index e0258cb..d9296ba 100644 (file)
@@ -50,6 +50,20 @@ RenderPtr<RenderElement> HTMLAttachmentElement::createElementRenderer(Ref<Render
 {
     return createRenderer<RenderAttachment>(*this, WTF::move(style));
 }
+    
+void HTMLAttachmentElement::setFocus(bool shouldBeFocused)
+{
+    if (focused() == shouldBeFocused)
+        return;
+    
+    HTMLElement::setFocus(shouldBeFocused);
+    
+    auto* renderer = this->renderer();
+    if (!is<RenderAttachment>(renderer))
+        return;
+    
+    downcast<RenderAttachment>(*renderer).focusChanged();
+}
 
 } // namespace WebCore
 
index 229d511..25d3cfd 100644 (file)
@@ -40,6 +40,9 @@ private:
     HTMLAttachmentElement(const QualifiedName&, Document&);
 
     virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&) override;
+
+    virtual bool isFocusable() const override { return true; }
+    virtual void setFocus(bool shouldBeFocused) override;
 };
 
 } // namespace WebCore
index dc8ca28..f709796 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(ATTACHMENT_ELEMENT)
 
 #include "FloatRect.h"
+#include "FrameSelection.h"
 #include "HTMLAttachmentElement.h"
 #include "PaintInfo.h"
 
@@ -50,11 +51,20 @@ void RenderAttachment::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
 {
     // FIXME: Implement
 
+    RefPtr<Range> selectionRange = frame().selection().selection().firstRange();
+    bool selected = selectionRange && selectionRange->intersectsNode(&nodeForNonAnonymous(), ASSERT_NO_EXCEPTION);
+    bool focused = frame().selection().isFocusedAndActive() && document().focusedElement() == &attachmentElement();
+
     paintInfo.context->save();
-    paintInfo.context->fillRect(FloatRect(paintOffset.x(), paintOffset.y(), 200, 200), Color::cyan, ColorSpaceSRGB);
+    paintInfo.context->fillRect(FloatRect(paintOffset.x(), paintOffset.y(), 200, 200), selected || focused ? Color::cyan : Color::lightGray, ColorSpaceSRGB);
     paintInfo.context->restore();
 }
 
+void RenderAttachment::focusChanged()
+{
+    repaint();
+}
+
 } // namespace WebCore
 
 #endif
index 4bcf97e..0c35fa4 100644 (file)
@@ -40,6 +40,8 @@ public:
 
     HTMLAttachmentElement& attachmentElement() const;
 
+    void focusChanged();
+
 private:
     void element() const = delete;
     virtual bool isAttachment() const override { return true; }