Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: Source/WebCore/html/HTMLDialogElement.cpp

Issue 13792002: Fix <dialog> centering (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: use hasCustomStyleCallbacks Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/WebCore/html/HTMLDialogElement.h ('k') | Source/WebCore/rendering/RenderDialog.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 10 matching lines...) Expand all
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #if ENABLE(DIALOG_ELEMENT) 27 #if ENABLE(DIALOG_ELEMENT)
28 #include "HTMLDialogElement.h" 28 #include "HTMLDialogElement.h"
29 29
30 #include "ExceptionCode.h" 30 #include "ExceptionCode.h"
31 #include "RenderDialog.h" 31 #include "FrameView.h"
32 #include "RenderBlock.h"
33 #include "RenderStyle.h"
34 #include "StyleResolver.h"
32 35
33 namespace WebCore { 36 namespace WebCore {
34 37
35 using namespace HTMLNames; 38 using namespace HTMLNames;
36 39
37 HTMLDialogElement::HTMLDialogElement(const QualifiedName& tagName, Document* doc ument) 40 HTMLDialogElement::HTMLDialogElement(const QualifiedName& tagName, Document* doc ument)
38 : HTMLElement(tagName, document) 41 : HTMLElement(tagName, document)
42 , m_topIsValid(false)
43 , m_top(0)
39 { 44 {
40 ASSERT(hasTagName(dialogTag)); 45 ASSERT(hasTagName(dialogTag));
46 setHasCustomStyleCallbacks();
41 ScriptWrappable::init(this); 47 ScriptWrappable::init(this);
42 } 48 }
43 49
44 PassRefPtr<HTMLDialogElement> HTMLDialogElement::create(const QualifiedName& tag Name, Document* document) 50 PassRefPtr<HTMLDialogElement> HTMLDialogElement::create(const QualifiedName& tag Name, Document* document)
45 { 51 {
46 return adoptRef(new HTMLDialogElement(tagName, document)); 52 return adoptRef(new HTMLDialogElement(tagName, document));
47 } 53 }
48 54
49 void HTMLDialogElement::close(ExceptionCode& ec) 55 void HTMLDialogElement::close(ExceptionCode& ec)
50 { 56 {
51 if (!fastHasAttribute(openAttr)) { 57 if (!fastHasAttribute(openAttr)) {
52 ec = INVALID_STATE_ERR; 58 ec = INVALID_STATE_ERR;
53 return; 59 return;
54 } 60 }
55 setBooleanAttribute(openAttr, false); 61 setBooleanAttribute(openAttr, false);
56 document()->removeFromTopLayer(this); 62 document()->removeFromTopLayer(this);
63 m_topIsValid = false;
64 }
65
66 PassRefPtr<RenderStyle> HTMLDialogElement::customStyleForRenderer()
67 {
68 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle ment(this);
69 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
70
71 // Override top to remain centered after style recalcs.
72 if (style->position() == AbsolutePosition && style->top().isAuto() && style- >bottom().isAuto()) {
esprehn 2013/04/16 08:32:06 Can you put this check in a static helper method?
falken 2013/04/16 12:02:14 Done.
73 if (m_topIsValid)
74 style->setTop(Length(m_top.toInt(), WebCore::Fixed));
75 }
76
77 return style.release();
78 }
79
80 void HTMLDialogElement::setupDefaultUnanchoredPosition()
esprehn 2013/04/16 08:32:06 I might rename this positionAndReattach(), it's no
falken 2013/04/16 12:02:14 Done.
81 {
82 ASSERT(!m_topIsValid);
83
84 // Layout because we need to know our ancestors' positions and our own heigh t.
85 document()->updateLayoutIgnorePendingStylesheets();
86
87 if (!renderer())
88 return;
89 RenderStyle* styleToUse = renderer()->style();
90 if (styleToUse->position() != AbsolutePosition || !styleToUse->top().isAuto( ) || !styleToUse->bottom().isAuto())
91 return;
92 RenderBlock* block = toRenderBlock(renderer());
esprehn 2013/04/16 08:32:06 I'd use a renderBox() method instead and RenderBox
falken 2013/04/16 12:02:14 Done.
93
94 // Set up dialog's position to be safe-centered in the viewport.
95 // FIXME: Figure out what to do in vertical writing mode.
96 FrameView* frameView = document()->view();
97 int scrollTop = frameView->scrollOffset().height();
98 FloatPoint absolutePoint(0, scrollTop);
99 int visibleHeight = frameView->visibleContentRect(ScrollableArea::IncludeScr ollbars).height();
100 if (block->height() < visibleHeight)
101 absolutePoint.move(0, (visibleHeight - block->height()) / 2);
102 FloatPoint localPoint = block->containingBlock()->absoluteToLocal(absolutePo int);
103
104 m_top = LayoutSize(localPoint.x(), localPoint.y()).height();
105 m_topIsValid = true;
106 reattach();
esprehn 2013/04/16 08:32:06 You might add a FIXME here. We can instead mutate
falken 2013/04/16 12:02:14 Done.
57 } 107 }
58 108
59 void HTMLDialogElement::show() 109 void HTMLDialogElement::show()
60 { 110 {
61 if (fastHasAttribute(openAttr)) 111 if (fastHasAttribute(openAttr))
62 return; 112 return;
63 setBooleanAttribute(openAttr, true); 113 setBooleanAttribute(openAttr, true);
114 setupDefaultUnanchoredPosition();
esprehn 2013/04/16 08:32:06 You can trivially make this assert by doing dialog
falken 2013/04/16 12:02:14 Good point. I removed the assert and added a test
64 } 115 }
65 116
66 void HTMLDialogElement::showModal(ExceptionCode& ec) 117 void HTMLDialogElement::showModal(ExceptionCode& ec)
67 { 118 {
68 if (fastHasAttribute(openAttr) || !inDocument()) { 119 if (fastHasAttribute(openAttr) || !inDocument()) {
69 ec = INVALID_STATE_ERR; 120 ec = INVALID_STATE_ERR;
70 return; 121 return;
71 } 122 }
123 document()->addToTopLayer(this);
72 setBooleanAttribute(openAttr, true); 124 setBooleanAttribute(openAttr, true);
73 document()->addToTopLayer(this); 125 setupDefaultUnanchoredPosition();
74 } 126 }
75 127
76 bool HTMLDialogElement::isPresentationAttribute(const QualifiedName& name) const 128 bool HTMLDialogElement::isPresentationAttribute(const QualifiedName& name) const
77 { 129 {
78 // FIXME: Workaround for <https://bugs.webkit.org/show_bug.cgi?id=91058>: mo difying an attribute for which there is an attribute selector 130 // FIXME: Workaround for <https://bugs.webkit.org/show_bug.cgi?id=91058>: mo difying an attribute for which there is an attribute selector
79 // in html.css sometimes does not trigger a style recalc. 131 // in html.css sometimes does not trigger a style recalc.
80 if (name == openAttr) 132 if (name == openAttr)
81 return true; 133 return true;
82 134
83 return HTMLElement::isPresentationAttribute(name); 135 return HTMLElement::isPresentationAttribute(name);
84 } 136 }
85 137
86 RenderObject* HTMLDialogElement::createRenderer(RenderArena* arena, RenderStyle* )
87 {
88 return new (arena) RenderDialog(this);
89 }
90
91 } 138 }
92 139
93 #endif 140 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/html/HTMLDialogElement.h ('k') | Source/WebCore/rendering/RenderDialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698