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

Side by Side Diff: sky/engine/core/dom/Element.cpp

Issue 1017593005: Add a basic custom painting facility to Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add missing files Created 5 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public 11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either 12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version. 13 * version 2 of the License, or (at your option) any later version.
14 * 14 *
15 * This library is distributed in the hope that it will be useful, 15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details. 18 * Library General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU Library General Public License 20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to 21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA. 23 * Boston, MA 02110-1301, USA.
24 */ 24 */
25 25
26 #include "sky/engine/config.h" 26 #include "sky/engine/config.h"
27 #include "sky/engine/core/dom/Element.h" 27 #include "sky/engine/core/dom/Element.h"
28 28
29 #include "base/bind.h"
29 #include "gen/sky/core/CSSValueKeywords.h" 30 #include "gen/sky/core/CSSValueKeywords.h"
30 #include "gen/sky/core/HTMLNames.h" 31 #include "gen/sky/core/HTMLNames.h"
31 #include "gen/sky/platform/RuntimeEnabledFeatures.h" 32 #include "gen/sky/platform/RuntimeEnabledFeatures.h"
32 #include "sky/engine/bindings/exception_messages.h" 33 #include "sky/engine/bindings/exception_messages.h"
33 #include "sky/engine/bindings/exception_state.h" 34 #include "sky/engine/bindings/exception_state.h"
34 #include "sky/engine/core/animation/AnimationTimeline.h" 35 #include "sky/engine/core/animation/AnimationTimeline.h"
35 #include "sky/engine/core/animation/css/CSSAnimations.h" 36 #include "sky/engine/core/animation/css/CSSAnimations.h"
36 #include "sky/engine/core/css/CSSImageValue.h" 37 #include "sky/engine/core/css/CSSImageValue.h"
37 #include "sky/engine/core/css/CSSStyleSheet.h" 38 #include "sky/engine/core/css/CSSStyleSheet.h"
38 #include "sky/engine/core/css/CSSValuePool.h" 39 #include "sky/engine/core/css/CSSValuePool.h"
39 #include "sky/engine/core/css/PropertySetCSSStyleDeclaration.h" 40 #include "sky/engine/core/css/PropertySetCSSStyleDeclaration.h"
40 #include "sky/engine/core/css/StylePropertySet.h" 41 #include "sky/engine/core/css/StylePropertySet.h"
41 #include "sky/engine/core/css/parser/BisonCSSParser.h" 42 #include "sky/engine/core/css/parser/BisonCSSParser.h"
42 #include "sky/engine/core/css/resolver/StyleResolver.h" 43 #include "sky/engine/core/css/resolver/StyleResolver.h"
43 #include "sky/engine/core/dom/Attr.h" 44 #include "sky/engine/core/dom/Attr.h"
44 #include "sky/engine/core/dom/ClientRect.h" 45 #include "sky/engine/core/dom/ClientRect.h"
45 #include "sky/engine/core/dom/ClientRectList.h" 46 #include "sky/engine/core/dom/ClientRectList.h"
46 #include "sky/engine/core/dom/DOMTokenList.h" 47 #include "sky/engine/core/dom/DOMTokenList.h"
47 #include "sky/engine/core/dom/Document.h" 48 #include "sky/engine/core/dom/Document.h"
48 #include "sky/engine/core/dom/ElementDataCache.h" 49 #include "sky/engine/core/dom/ElementDataCache.h"
49 #include "sky/engine/core/dom/ElementRareData.h" 50 #include "sky/engine/core/dom/ElementRareData.h"
50 #include "sky/engine/core/dom/ElementTraversal.h" 51 #include "sky/engine/core/dom/ElementTraversal.h"
51 #include "sky/engine/core/dom/ExceptionCode.h" 52 #include "sky/engine/core/dom/ExceptionCode.h"
53 #include "sky/engine/core/dom/Microtask.h"
52 #include "sky/engine/core/dom/MutationObserverInterestGroup.h" 54 #include "sky/engine/core/dom/MutationObserverInterestGroup.h"
53 #include "sky/engine/core/dom/MutationRecord.h" 55 #include "sky/engine/core/dom/MutationRecord.h"
54 #include "sky/engine/core/dom/NodeRenderStyle.h" 56 #include "sky/engine/core/dom/NodeRenderStyle.h"
55 #include "sky/engine/core/dom/RenderTreeBuilder.h" 57 #include "sky/engine/core/dom/RenderTreeBuilder.h"
56 #include "sky/engine/core/dom/SelectorQuery.h" 58 #include "sky/engine/core/dom/SelectorQuery.h"
57 #include "sky/engine/core/dom/StyleEngine.h" 59 #include "sky/engine/core/dom/StyleEngine.h"
58 #include "sky/engine/core/dom/Text.h" 60 #include "sky/engine/core/dom/Text.h"
59 #include "sky/engine/core/dom/custom/custom_element.h" 61 #include "sky/engine/core/dom/custom/custom_element.h"
60 #include "sky/engine/core/dom/shadow/InsertionPoint.h" 62 #include "sky/engine/core/dom/shadow/InsertionPoint.h"
61 #include "sky/engine/core/dom/shadow/ShadowRoot.h" 63 #include "sky/engine/core/dom/shadow/ShadowRoot.h"
62 #include "sky/engine/core/editing/FrameSelection.h" 64 #include "sky/engine/core/editing/FrameSelection.h"
63 #include "sky/engine/core/editing/TextIterator.h" 65 #include "sky/engine/core/editing/TextIterator.h"
64 #include "sky/engine/core/editing/htmlediting.h" 66 #include "sky/engine/core/editing/htmlediting.h"
65 #include "sky/engine/core/events/EventDispatcher.h" 67 #include "sky/engine/core/events/EventDispatcher.h"
66 #include "sky/engine/core/events/FocusEvent.h" 68 #include "sky/engine/core/events/FocusEvent.h"
67 #include "sky/engine/core/frame/FrameView.h" 69 #include "sky/engine/core/frame/FrameView.h"
68 #include "sky/engine/core/frame/LocalFrame.h" 70 #include "sky/engine/core/frame/LocalFrame.h"
69 #include "sky/engine/core/frame/Settings.h" 71 #include "sky/engine/core/frame/Settings.h"
70 #include "sky/engine/core/html/HTMLCanvasElement.h" 72 #include "sky/engine/core/html/HTMLCanvasElement.h"
71 #include "sky/engine/core/html/HTMLElement.h" 73 #include "sky/engine/core/html/HTMLElement.h"
72 #include "sky/engine/core/html/HTMLTemplateElement.h" 74 #include "sky/engine/core/html/HTMLTemplateElement.h"
73 #include "sky/engine/core/html/parser/HTMLDocumentParser.h" 75 #include "sky/engine/core/html/parser/HTMLDocumentParser.h"
74 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" 76 #include "sky/engine/core/html/parser/HTMLParserIdioms.h"
75 #include "sky/engine/core/page/ChromeClient.h" 77 #include "sky/engine/core/page/ChromeClient.h"
76 #include "sky/engine/core/page/FocusController.h" 78 #include "sky/engine/core/page/FocusController.h"
77 #include "sky/engine/core/page/Page.h" 79 #include "sky/engine/core/page/Page.h"
80 #include "sky/engine/core/painting/PaintingContext.h"
81 #include "sky/engine/core/painting/PaintingCallback.h"
78 #include "sky/engine/core/rendering/RenderLayer.h" 82 #include "sky/engine/core/rendering/RenderLayer.h"
79 #include "sky/engine/core/rendering/RenderView.h" 83 #include "sky/engine/core/rendering/RenderView.h"
80 #include "sky/engine/platform/EventDispatchForbiddenScope.h" 84 #include "sky/engine/platform/EventDispatchForbiddenScope.h"
81 #include "sky/engine/tonic/dart_state.h" 85 #include "sky/engine/tonic/dart_state.h"
82 #include "sky/engine/wtf/BitVector.h" 86 #include "sky/engine/wtf/BitVector.h"
83 #include "sky/engine/wtf/HashFunctions.h" 87 #include "sky/engine/wtf/HashFunctions.h"
84 #include "sky/engine/wtf/text/CString.h" 88 #include "sky/engine/wtf/text/CString.h"
85 #include "sky/engine/wtf/text/StringBuilder.h" 89 #include "sky/engine/wtf/text/StringBuilder.h"
86 #include "sky/engine/wtf/text/TextPosition.h" 90 #include "sky/engine/wtf/text/TextPosition.h"
87 91
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (quads.isEmpty()) 410 if (quads.isEmpty())
407 return ClientRect::create(); 411 return ClientRect::create();
408 412
409 FloatRect result = quads[0].boundingBox(); 413 FloatRect result = quads[0].boundingBox();
410 for (size_t i = 1; i < quads.size(); ++i) 414 for (size_t i = 1; i < quads.size(); ++i)
411 result.unite(quads[i].boundingBox()); 415 result.unite(quads[i].boundingBox());
412 416
413 return ClientRect::create(result); 417 return ClientRect::create(result);
414 } 418 }
415 419
420 // TODO(abarth): We should schedule this work at a more reasonable time.
421 static void handlePaintingCommit(RefPtr<Element> element, RefPtr<PaintingContext > context)
422 {
423 if (!element->document().isActive())
424 return;
425 element->document().updateLayout();
ojan 2015/03/19 22:30:04 We should not need to do this. I guess that falls
426 RenderObject* renderer = element->renderer();
427 if (!renderer || !renderer->isBox())
428 return;
429 toRenderBox(renderer)->setCustomPainting(context->takeDisplayList());
430 element->document().scheduleVisualUpdate();
431 }
432
433 // TODO(abarth): We should schedule this work at a more reasonable time.
434 static void runPaintingCallback(RefPtr<Element> element, PassOwnPtr<PaintingCall back> callback)
435 {
436 if (!element->document().isActive())
437 return;
438 element->document().updateLayout();
439 RenderObject* renderer = element->renderer();
440 if (!renderer || !renderer->isBox())
441 return;
442 RefPtr<PaintingContext> context = PaintingContext::create(
443 toRenderBox(renderer)->size(), base::Bind(&handlePaintingCommit, element ));
444 callback->handleEvent(context.get());
445 }
446
447 void Element::requestPaint(PassOwnPtr<PaintingCallback> callback)
448 {
449 Microtask::enqueueMicrotask(base::Bind(&runPaintingCallback, this, callback) );
450 }
451
416 void Element::setAttribute(const AtomicString& localName, const AtomicString& va lue, ExceptionState& exceptionState) 452 void Element::setAttribute(const AtomicString& localName, const AtomicString& va lue, ExceptionState& exceptionState)
417 { 453 {
418 if (!Document::isValidName(localName)) { 454 if (!Document::isValidName(localName)) {
419 exceptionState.ThrowDOMException(InvalidCharacterError, "'" + localName + "' is not a valid attribute name."); 455 exceptionState.ThrowDOMException(InvalidCharacterError, "'" + localName + "' is not a valid attribute name.");
420 return; 456 return;
421 } 457 }
422 458
423 synchronizeAttribute(localName); 459 synchronizeAttribute(localName);
424 460
425 if (!elementData()) { 461 if (!elementData()) {
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 return false; 1592 return false;
1557 if (treeScope().scopedStyleResolver().hasSelectorForId(idValue)) 1593 if (treeScope().scopedStyleResolver().hasSelectorForId(idValue))
1558 return true; 1594 return true;
1559 // Host rules could also have effects. 1595 // Host rules could also have effects.
1560 if (ShadowRoot* shadowRoot = this->shadowRoot()) 1596 if (ShadowRoot* shadowRoot = this->shadowRoot())
1561 return shadowRoot->scopedStyleResolver().hasSelectorForId(idValue); 1597 return shadowRoot->scopedStyleResolver().hasSelectorForId(idValue);
1562 return false; 1598 return false;
1563 } 1599 }
1564 1600
1565 } // namespace blink 1601 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698