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

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: fix use of PassRefPtr 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 static bool needsCenteredPositioning(const RenderStyle* style)
67 {
68 return style->position() == AbsolutePosition && style->hasAutoTopAndBottom() ;
69 }
70
71 PassRefPtr<RenderStyle> HTMLDialogElement::customStyleForRenderer()
72 {
73 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle ment(this);
74 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
75
76 // Override top to remain centered after style recalcs.
77 if (needsCenteredPositioning(style.get()) && m_topIsValid)
78 style->setTop(Length(m_top.toInt(), WebCore::Fixed));
Julien - ping for review 2013/04/17 22:12:25 Tab pointed out that this should respond to 'writi
falken 2013/04/18 01:46:57 Yes, this patch doesn't handle writing-mode yet. T
79
80 return style.release();
81 }
82
83 void HTMLDialogElement::positionAndReattach()
84 {
85 // Layout because we need to know our ancestors' positions and our own heigh t.
86 document()->updateLayoutIgnorePendingStylesheets();
87
88 RenderBox* box = renderBox();
89 if (!box)
90 return;
91 RenderStyle* styleToUse = box->style();
Julien - ping for review 2013/04/17 22:12:25 This variable is only used below so you could just
falken 2013/04/18 01:46:57 Done.
92 if (!needsCenteredPositioning(styleToUse))
93 return;
94
95 // Set up dialog's position to be safe-centered in the viewport.
96 // FIXME: Figure out what to do in vertical writing mode.
97 FrameView* frameView = document()->view();
98 int scrollTop = frameView->scrollOffset().height();
99 FloatPoint absolutePoint(0, scrollTop);
100 int visibleHeight = frameView->visibleContentRect(ScrollableArea::IncludeScr ollbars).height();
101 if (box->height() < visibleHeight)
102 absolutePoint.move(0, (visibleHeight - box->height()) / 2);
103 FloatPoint localPoint = box->containingBlock()->absoluteToLocal(absolutePoin t);
Julien - ping for review 2013/04/17 22:12:25 We discussed this with Elliot and Tab and think yo
falken 2013/04/18 01:46:57 Thanks for discussing this!! I'll work on reparent
104
105 m_top = LayoutSize(localPoint.x(), localPoint.y()).height();
Julien - ping for review 2013/04/17 22:12:25 m_top = localPoint.y(); !!!
falken 2013/04/18 01:46:57 Done.
106 m_topIsValid = true;
Julien - ping for review 2013/04/17 22:12:25 Currently you only handle m_top so it makes sense
falken 2013/04/18 01:46:57 Hmm.. let me handle this in the next patch. m_topI
107
108 // FIXME: It's inefficient to reattach here. We could do better by mutating style directly and forcing another layout.
109 reattach();
57 } 110 }
58 111
59 void HTMLDialogElement::show() 112 void HTMLDialogElement::show()
60 { 113 {
61 if (fastHasAttribute(openAttr)) 114 if (fastHasAttribute(openAttr))
62 return; 115 return;
63 setBooleanAttribute(openAttr, true); 116 setBooleanAttribute(openAttr, true);
117 positionAndReattach();
Julien - ping for review 2013/04/17 22:12:25 Is it normal that we also center on 'show'?
falken 2013/04/18 01:46:57 I'm not sure what you mean... we want to center wh
64 } 118 }
65 119
66 void HTMLDialogElement::showModal(ExceptionCode& ec) 120 void HTMLDialogElement::showModal(ExceptionCode& ec)
67 { 121 {
68 if (fastHasAttribute(openAttr) || !inDocument()) { 122 if (fastHasAttribute(openAttr) || !inDocument()) {
69 ec = INVALID_STATE_ERR; 123 ec = INVALID_STATE_ERR;
70 return; 124 return;
71 } 125 }
126 document()->addToTopLayer(this);
72 setBooleanAttribute(openAttr, true); 127 setBooleanAttribute(openAttr, true);
73 document()->addToTopLayer(this); 128 positionAndReattach();
74 } 129 }
75 130
76 bool HTMLDialogElement::isPresentationAttribute(const QualifiedName& name) const 131 bool HTMLDialogElement::isPresentationAttribute(const QualifiedName& name) const
77 { 132 {
78 // FIXME: Workaround for <https://bugs.webkit.org/show_bug.cgi?id=91058>: mo difying an attribute for which there is an attribute selector 133 // 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. 134 // in html.css sometimes does not trigger a style recalc.
80 if (name == openAttr) 135 if (name == openAttr)
81 return true; 136 return true;
82 137
83 return HTMLElement::isPresentationAttribute(name); 138 return HTMLElement::isPresentationAttribute(name);
84 } 139 }
85 140
86 RenderObject* HTMLDialogElement::createRenderer(RenderArena* arena, RenderStyle* )
87 {
88 return new (arena) RenderDialog(this);
89 }
90
91 } 141 }
92 142
93 #endif 143 #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