Changeset 127681 in webkit


Ignore:
Timestamp:
Sep 5, 2012 7:24:08 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Vertically center non-anchored <dialog> elements
https://bugs.webkit.org/show_bug.cgi?id=90670

Patch by Matt Falkenhagen <falken@chromium.org> on 2012-09-05
Reviewed by Ojan Vafai.

Source/WebCore:

This adjusts the static default position of non-anchored
dialog elements so they are vertically centered in or at the top of
the viewport, as per the spec.

The approach is to add a RenderDialog class whose layout()
function adjusts the position after normal RenderBlock::layout runs.

Test: fast/dom/HTMLDialogElement/non-anchored-dialog-positioning.html

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.xcodeproj/project.pbxproj:
  • html/HTMLDialogElement.cpp:

(WebCore::HTMLDialogElement::createRenderer):
(WebCore):

  • html/HTMLDialogElement.h:

(HTMLDialogElement):

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::mapAbsoluteToLocalPoint): Remove assertion since now absoluteToLocal is called during layout.

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::mapAbsoluteToLocalPoint): Ditto.

  • rendering/RenderDialog.cpp: Added.

(WebCore):
(WebCore::RenderDialog::layout): Compute the desired top position in the absolute coordinate system, and then set top to the
corresponding local coordinate.

  • rendering/RenderDialog.h: Added.

(WebCore):
(RenderDialog):
(WebCore::RenderDialog::RenderDialog):
(WebCore::RenderDialog::~RenderDialog):
(WebCore::RenderDialog::renderName):

  • rendering/RenderObject.h:

(RenderObject):
(WebCore::RenderObject::isDialog):

  • rendering/RenderingAllInOne.cpp:

LayoutTests:

  • fast/dom/HTMLDialogElement/non-anchored-dialog-positioning-expected.txt: Added.
  • fast/dom/HTMLDialogElement/non-anchored-dialog-positioning.html: Added.
Location:
trunk
Files:
2 added
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r127679 r127681  
     12012-09-05  Matt Falkenhagen  <falken@chromium.org>
     2
     3        Vertically center non-anchored <dialog> elements
     4        https://bugs.webkit.org/show_bug.cgi?id=90670
     5
     6        Reviewed by Ojan Vafai.
     7
     8        * fast/dom/HTMLDialogElement/non-anchored-dialog-positioning-expected.txt: Added.
     9        * fast/dom/HTMLDialogElement/non-anchored-dialog-positioning.html: Added.
     10
    1112012-09-05  Kenichi Ishibashi  <bashi@chromium.org>
    212
  • trunk/Source/WebCore/CMakeLists.txt

    r127679 r127681  
    20362036    rendering/RenderDeprecatedFlexibleBox.cpp
    20372037    rendering/RenderDetailsMarker.cpp
     2038    rendering/RenderDialog.cpp
    20382039    rendering/RenderEmbeddedObject.cpp
    20392040    rendering/RenderFieldset.cpp
  • trunk/Source/WebCore/ChangeLog

    r127679 r127681  
     12012-09-05  Matt Falkenhagen  <falken@chromium.org>
     2
     3        Vertically center non-anchored <dialog> elements
     4        https://bugs.webkit.org/show_bug.cgi?id=90670
     5
     6        Reviewed by Ojan Vafai.
     7
     8        This adjusts the static default position of non-anchored
     9        dialog elements so they are vertically centered in or at the top of
     10        the viewport, as per the spec.
     11
     12        The approach is to add a RenderDialog class whose layout()
     13        function adjusts the position after normal RenderBlock::layout runs.
     14
     15        Test: fast/dom/HTMLDialogElement/non-anchored-dialog-positioning.html
     16
     17        * CMakeLists.txt:
     18        * GNUmakefile.list.am:
     19        * Target.pri:
     20        * WebCore.gypi:
     21        * WebCore.xcodeproj/project.pbxproj:
     22        * html/HTMLDialogElement.cpp:
     23        (WebCore::HTMLDialogElement::createRenderer):
     24        (WebCore):
     25        * html/HTMLDialogElement.h:
     26        (HTMLDialogElement):
     27        * rendering/RenderBox.cpp:
     28        (WebCore::RenderBox::mapAbsoluteToLocalPoint): Remove assertion since now absoluteToLocal is called during layout.
     29        * rendering/RenderBoxModelObject.cpp:
     30        (WebCore::RenderBoxModelObject::mapAbsoluteToLocalPoint): Ditto.
     31        * rendering/RenderDialog.cpp: Added.
     32        (WebCore):
     33        (WebCore::RenderDialog::layout): Compute the desired top position in the absolute coordinate system, and then set top to the
     34        corresponding local coordinate.
     35        * rendering/RenderDialog.h: Added.
     36        (WebCore):
     37        (RenderDialog):
     38        (WebCore::RenderDialog::RenderDialog):
     39        (WebCore::RenderDialog::~RenderDialog):
     40        (WebCore::RenderDialog::renderName):
     41        * rendering/RenderObject.h:
     42        (RenderObject):
     43        (WebCore::RenderObject::isDialog):
     44        * rendering/RenderingAllInOne.cpp:
     45
    1462012-09-05  Kenichi Ishibashi  <bashi@chromium.org>
    247
  • trunk/Source/WebCore/GNUmakefile.list.am

    r127679 r127681  
    49114911        Source/WebCore/rendering/RenderDetailsMarker.cpp \
    49124912        Source/WebCore/rendering/RenderDetailsMarker.h \
     4913        Source/WebCore/rendering/RenderDialog.h \
    49134914        Source/WebCore/rendering/RenderEmbeddedObject.cpp \
    49144915        Source/WebCore/rendering/RenderEmbeddedObject.h \
  • trunk/Source/WebCore/Target.pri

    r127579 r127681  
    11171117    rendering/RenderDeprecatedFlexibleBox.cpp \
    11181118    rendering/RenderDetailsMarker.cpp \
     1119    rendering/RenderDialog.cpp \
    11191120    rendering/RenderEmbeddedObject.cpp \
    11201121    rendering/RenderFieldset.cpp \
  • trunk/Source/WebCore/WebCore.gypi

    r127679 r127681  
    566566            'rendering/RenderBox.h',
    567567            'rendering/RenderBoxModelObject.h',
     568            'rendering/RenderDialog.h',
    568569            'rendering/RenderEmbeddedObject.h',
    569570            'rendering/RenderFlowThread.h',
     
    47354736            'rendering/RenderDetailsMarker.cpp',
    47364737            'rendering/RenderDetailsMarker.h',
     4738            'rendering/RenderDialog.cpp',
    47374739            'rendering/RenderEmbeddedObject.cpp',
    47384740            'rendering/RenderFieldset.cpp',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r127535 r127681  
    19111911                76CDD2F61103DA6600680521 /* AccessibilityMenuListOption.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76CDD2F01103DA6600680521 /* AccessibilityMenuListOption.cpp */; };
    19121912                76CDD2F71103DA6600680521 /* AccessibilityMenuListOption.h in Headers */ = {isa = PBXBuildFile; fileRef = 76CDD2F11103DA6600680521 /* AccessibilityMenuListOption.h */; };
     1913                76F2E2EB15F74CEF005FF664 /* RenderDialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76F2E2E915F74CEF005FF664 /* RenderDialog.cpp */; };
     1914                76F2E2EC15F74CEF005FF664 /* RenderDialog.h in Headers */ = {isa = PBXBuildFile; fileRef = 76F2E2EA15F74CEF005FF664 /* RenderDialog.h */; };
    19131915                76FC2B0B12370DA0006A991A /* DOMTokenList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B0812370DA0006A991A /* DOMTokenList.cpp */; };
    19141916                76FC2B0C12370DA0006A991A /* DOMTokenList.h in Headers */ = {isa = PBXBuildFile; fileRef = 76FC2B0912370DA0006A991A /* DOMTokenList.h */; };
     
    90969098                76CDD2F01103DA6600680521 /* AccessibilityMenuListOption.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityMenuListOption.cpp; sourceTree = "<group>"; };
    90979099                76CDD2F11103DA6600680521 /* AccessibilityMenuListOption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityMenuListOption.h; sourceTree = "<group>"; };
     9100                76F2E2E915F74CEF005FF664 /* RenderDialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderDialog.cpp; sourceTree = "<group>"; };
     9101                76F2E2EA15F74CEF005FF664 /* RenderDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderDialog.h; sourceTree = "<group>"; };
    90989102                76FC2B0812370DA0006A991A /* DOMTokenList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMTokenList.cpp; sourceTree = "<group>"; };
    90999103                76FC2B0912370DA0006A991A /* DOMTokenList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMTokenList.h; sourceTree = "<group>"; };
     
    2134021344                                D302754512A5FE84004BD828 /* RenderDetailsMarker.cpp */,
    2134121345                                D302754612A5FE84004BD828 /* RenderDetailsMarker.h */,
     21346                                76F2E2E915F74CEF005FF664 /* RenderDialog.cpp */,
     21347                                76F2E2EA15F74CEF005FF664 /* RenderDialog.h */,
    2134221348                                0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */,
    2134321349                                0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */,
     
    2549125497                                FBD6AF8A15EF25DF008B7110 /* BasicShapeFunctions.h in Headers */,
    2549225498                                FBD6AF8C15EF2604008B7110 /* BasicShapes.h in Headers */,
     25499                                76F2E2EC15F74CEF005FF664 /* RenderDialog.h in Headers */,
    2549325500                        );
    2549425501                        runOnlyForDeploymentPostprocessing = 0;
     
    2858028587                                377A3A9015EFCE9B0059F5C7 /* BitmapImageCG.cpp in Sources */,
    2858128588                                BCD8A5F015F56F2C0098D071 /* TextBreakIterator.cpp in Sources */,
     28589                                76F2E2EB15F74CEF005FF664 /* RenderDialog.cpp in Sources */,
    2858228590                        );
    2858328591                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/html/HTMLDialogElement.cpp

    r123193 r127681  
    3030
    3131#include "ExceptionCode.h"
     32#include "RenderDialog.h"
    3233
    3334namespace WebCore {
     
    7273}
    7374
     75RenderObject* HTMLDialogElement::createRenderer(RenderArena* arena, RenderStyle*)
     76{
     77    return new (arena) RenderDialog(this);
     78}
     79
    7480}
    7581
  • trunk/Source/WebCore/html/HTMLDialogElement.h

    r123193 r127681  
    4646    HTMLDialogElement(const QualifiedName&, Document*);
    4747
     48    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) OVERRIDE;
    4849    virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
    4950};
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r127596 r127681  
    13551355void RenderBox::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
    13561356{
    1357     // We don't expect absoluteToLocal() to be called during layout (yet)
    1358     ASSERT(!view() || !view()->layoutStateEnabled());
    1359    
    13601357    bool isFixedPos = style()->position() == FixedPosition;
    13611358    bool hasTransform = hasLayer() && layer()->transform();
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r127497 r127681  
    28322832void RenderBoxModelObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
    28332833{
    2834     // We don't expect absoluteToLocal() to be called during layout (yet)
    2835     ASSERT(!view() || !view()->layoutStateEnabled());
    2836 
    28372834    RenderObject* o = container();
    28382835    if (!o)
  • trunk/Source/WebCore/rendering/RenderDialog.cpp

    r127680 r127681  
    2525
    2626#include "config.h"
    27 #include "HTMLDialogElement.h"
     27#include "RenderDialog.h"
    2828
    2929#if ENABLE(DIALOG_ELEMENT)
    30 
    31 #include "ExceptionCode.h"
     30#include "FrameView.h"
     31#include "LayoutRepainter.h"
     32#include "RenderLayer.h"
     33#include "RenderView.h"
    3234
    3335namespace WebCore {
    3436
    35 using namespace HTMLNames;
     37void RenderDialog::layout()
     38{
     39    LayoutRepainter repainter(*this, true);
     40    LayoutStateMaintainer statePusher(view(), this, locationOffset(), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode());
    3641
    37 HTMLDialogElement::HTMLDialogElement(const QualifiedName& tagName, Document* document)
    38     : HTMLElement(tagName, document)
    39 {
    40     ASSERT(hasTagName(dialogTag));
    41 }
     42    RenderBlock::layout();
    4243
    43 PassRefPtr<HTMLDialogElement> HTMLDialogElement::create(const QualifiedName& tagName, Document* document)
    44 {
    45     return adoptRef(new HTMLDialogElement(tagName, document));
    46 }
    47 
    48 void HTMLDialogElement::close(ExceptionCode& ec)
    49 {
    50     if (!fastHasAttribute(openAttr)) {
    51         ec = INVALID_STATE_ERR;
     44    RenderStyle* styleToUse = style();
     45    if (styleToUse->position() != AbsolutePosition || !styleToUse->top().isAuto() || !styleToUse->bottom().isAuto()) {
     46        statePusher.pop();
    5247        return;
    5348    }
    54     setBooleanAttribute(openAttr, false);
    55 }
    5649
    57 void HTMLDialogElement::show()
    58 {
    59     if (fastHasAttribute(openAttr))
    60         return;
    61     setBooleanAttribute(openAttr, true);
    62 }
     50    // Adjust the dialog's position to be centered in or at the top of the viewport.
     51    // FIXME: Figure out what to do in vertical writing mode.
     52    FrameView* frameView = document()->view();
     53    int scrollTop = frameView->scrollOffset().height();
     54    FloatPoint absolutePoint(0, scrollTop);
     55    int visibleHeight = frameView->visibleContentRect(true).height();
     56    if (height() < visibleHeight)
     57        absolutePoint.move(0, (visibleHeight - height()) / 2);
     58    FloatPoint localPoint = containingBlock()->absoluteToLocal(absolutePoint);
     59    LayoutUnit localTop = LayoutSize(localPoint.x(), localPoint.y()).height();
     60    setY(localTop);
    6361
    64 bool HTMLDialogElement::isPresentationAttribute(const QualifiedName& name) const
    65 {
    66     // FIXME: Workaround for <https://bugs.webkit.org/show_bug.cgi?id=91058>: modifying an attribute for which there is an attribute selector
    67     // in html.css sometimes does not trigger a style recalc.
    68     if (name == openAttr)
    69         return true;
    70 
    71     return HTMLElement::isPresentationAttribute(name);
     62    statePusher.pop();
     63    // FIXME: Since there is always a layer here, repainter shouldn't be necessary. But without it, the dialog is sometimes not painted (see bug 90670).
     64    repainter.repaintAfterLayout();
    7265}
    7366
  • trunk/Source/WebCore/rendering/RenderDialog.h

    r127680 r127681  
    2424 */
    2525
    26 #ifndef HTMLDialogElement_h
    27 #define HTMLDialogElement_h
     26#ifndef RenderDialog_h
     27#define RenderDialog_h
    2828
    2929#if ENABLE(DIALOG_ELEMENT)
    30 
    31 #include "HTMLElement.h"
     30#include "RenderBlock.h"
     31#include "RenderWidget.h"
    3232
    3333namespace WebCore {
    3434
    35 class Document;
    36 class QualifiedName;
     35class HTMLDialogElement;
    3736
    38 class HTMLDialogElement : public HTMLElement {
     37class RenderDialog : public RenderBlock {
    3938public:
    40     static PassRefPtr<HTMLDialogElement> create(const QualifiedName&, Document*);
     39    explicit RenderDialog(Node* node)
     40        : RenderBlock(node)
     41    { }
    4142
    42     void close(ExceptionCode&);
    43     void show();
     43    virtual ~RenderDialog() { }
     44    virtual void layout() OVERRIDE;
    4445
    4546private:
    46     HTMLDialogElement(const QualifiedName&, Document*);
    47 
    48     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
     47    virtual const char* renderName() const { return "RenderDialog"; }
     48    virtual bool isDialog() const OVERRIDE { return true; }
    4949};
    5050
     
    5353#endif
    5454
    55 #endif
     55#endif // RenderDialog_h
  • trunk/Source/WebCore/rendering/RenderObject.h

    r127608 r127681  
    312312    virtual bool isBoxModelObject() const { return false; }
    313313    virtual bool isCounter() const { return false; }
     314#if ENABLE(DIALOG_ELEMENT)
     315    virtual bool isDialog() const { return false; }
     316#endif
    314317    virtual bool isQuote() const { return false; }
    315318
  • trunk/Source/WebCore/rendering/RenderingAllInOne.cpp

    r120569 r127681  
    5252#include "RenderDeprecatedFlexibleBox.cpp"
    5353#include "RenderDetailsMarker.cpp"
     54#include "RenderDialog.cpp"
    5455#include "RenderEmbeddedObject.cpp"
    5556#include "RenderFieldset.cpp"
Note: See TracChangeset for help on using the changeset viewer.