OLD | NEW |
---|---|
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 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 } | 335 } |
336 | 336 |
337 static void printNavigationErrorMessage(const Frame& frame, const KURL& activeUR L, const char* reason) | 337 static void printNavigationErrorMessage(const Frame& frame, const KURL& activeUR L, const char* reason) |
338 { | 338 { |
339 String message = "Unsafe JavaScript attempt to initiate navigation for frame with URL '" + frame.document()->url().string() + "' from frame with URL '" + ac tiveURL.string() + "'. " + reason + "\n"; | 339 String message = "Unsafe JavaScript attempt to initiate navigation for frame with URL '" + frame.document()->url().string() + "' from frame with URL '" + ac tiveURL.string() + "'. " + reason + "\n"; |
340 | 340 |
341 // FIXME: should we print to the console of the document performing the navi gation instead? | 341 // FIXME: should we print to the console of the document performing the navi gation instead? |
342 frame.domWindow()->printErrorMessage(message); | 342 frame.domWindow()->printErrorMessage(message); |
343 } | 343 } |
344 | 344 |
345 // Decide which element that is to define the viewport's overflow policy. Any pa rameter may be | |
346 // 0. Avoid calling Element::renderStyle() here; require style as separate param eters instead. The | |
347 // reason for this is that style may not have been associated with the elements yet - in which case | |
348 // it may have been calculated on the fly (without associating it with the actua l element) | |
349 // somewhere. This isn't very pretty, but if we want to avoid duplicating the co de that chooses | |
350 // between root and body for overflow propagation, this is about as pretty as it gets. | |
rune
2014/02/07 16:44:27
You could consolidate this code with the viewportD
mstensho (USE GERRIT)
2014/02/11 10:44:14
Done.
| |
351 // The |bodyElement| passed must either be 0 or set to the document's primary bo dy element. | |
352 static Element* pickViewportDefiningElement(Element* rootElement, RenderStyle* r ootStyle, Element* bodyElement, RenderStyle* bodyStyle) | |
ojan
2014/02/08 01:40:19
Do we need to pass the RenderStyles? Can't we just
mstensho (USE GERRIT)
2014/02/11 10:44:14
That's not always going to work. The comment tries
| |
353 { | |
354 // If a BODY element sets non-visible overflow, it is to be propagated to th e viewport, as long | |
355 // as the following conditions are all met: | |
356 // (1) The root element is HTML. | |
357 // (2) It is the primary BODY element (we only assert for this, expecting ca llers to behave). | |
358 // (3) The root element has visible overflow. | |
359 // Otherwise it's the root element's properties that are to be propagated. | |
360 if (!rootElement || !rootStyle) | |
361 return 0; | |
362 ASSERT(!bodyElement || bodyElement == bodyElement->document().body()); | |
363 if (bodyElement && bodyStyle && rootStyle->isOverflowVisible() && rootElemen t->hasTagName(htmlTag)) | |
364 return bodyElement; | |
365 return rootElement; | |
366 } | |
367 | |
345 uint64_t Document::s_globalTreeVersion = 0; | 368 uint64_t Document::s_globalTreeVersion = 0; |
346 | 369 |
347 // This class doesn't work with non-Document ExecutionContext. | 370 // This class doesn't work with non-Document ExecutionContext. |
348 class AutofocusTask FINAL : public ExecutionContextTask { | 371 class AutofocusTask FINAL : public ExecutionContextTask { |
349 public: | 372 public: |
350 static PassOwnPtr<AutofocusTask> create() | 373 static PassOwnPtr<AutofocusTask> create() |
351 { | 374 { |
352 return adoptPtr(new AutofocusTask()); | 375 return adoptPtr(new AutofocusTask()); |
353 } | 376 } |
354 virtual ~AutofocusTask() { } | 377 virtual ~AutofocusTask() { } |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1598 } | 1621 } |
1599 Node* root = node; | 1622 Node* root = node; |
1600 while (Node* host = root->shadowHost()) | 1623 while (Node* host = root->shadowHost()) |
1601 root = host; | 1624 root = host; |
1602 while (Node* ancestor = root->parentOrShadowHostNode()) | 1625 while (Node* ancestor = root->parentOrShadowHostNode()) |
1603 root = ancestor; | 1626 root = ancestor; |
1604 if (root->childNeedsDistributionRecalc()) | 1627 if (root->childNeedsDistributionRecalc()) |
1605 root->recalcDistribution(); | 1628 root->recalcDistribution(); |
1606 } | 1629 } |
1607 | 1630 |
1608 void Document::setStyleDependentState(RenderStyle* documentStyle) | 1631 void Document::setStyleDependentState(RenderStyle* documentStyle) |
ojan
2014/02/08 01:40:19
Nit: maybe rename this method to setupFontBuilder
mstensho (USE GERRIT)
2014/02/11 10:44:14
Done.
| |
1609 { | 1632 { |
1610 const Pagination& pagination = view()->pagination(); | |
1611 if (pagination.mode != Pagination::Unpaginated) { | |
1612 Pagination::setStylesForPaginationMode(pagination.mode, documentStyle); | |
1613 documentStyle->setColumnGap(pagination.gap); | |
1614 if (renderView()->hasColumns()) | |
1615 renderView()->updateColumnInfoFromStyle(documentStyle); | |
1616 } | |
1617 | |
1618 FontBuilder fontBuilder; | 1633 FontBuilder fontBuilder; |
1619 fontBuilder.initForStyleResolve(*this, documentStyle, isSVGDocument()); | 1634 fontBuilder.initForStyleResolve(*this, documentStyle, isSVGDocument()); |
1620 RefPtr<CSSFontSelector> selector = m_styleEngine->fontSelector(); | 1635 RefPtr<CSSFontSelector> selector = m_styleEngine->fontSelector(); |
1621 fontBuilder.createFontForDocument(selector, documentStyle); | 1636 fontBuilder.createFontForDocument(selector, documentStyle); |
1622 } | 1637 } |
1623 | 1638 |
1624 void Document::inheritHtmlAndBodyElementStyles(StyleRecalcChange change) | 1639 void Document::inheritHtmlAndBodyElementStyles(StyleRecalcChange change) |
1625 { | 1640 { |
1626 ASSERT(inStyleRecalc()); | 1641 ASSERT(inStyleRecalc()); |
1627 ASSERT(documentElement()); | 1642 ASSERT(documentElement()); |
1628 | 1643 |
1629 RefPtr<RenderStyle> documentElementStyle = documentElement()->renderStyle(); | 1644 RefPtr<RenderStyle> documentElementStyle = documentElement()->renderStyle(); |
1630 if (!documentElementStyle || documentElement()->needsStyleRecalc() || change == Force) | 1645 if (!documentElementStyle || documentElement()->needsStyleRecalc() || change == Force) |
1631 documentElementStyle = ensureStyleResolver().styleForElement(documentEle ment()); | 1646 documentElementStyle = ensureStyleResolver().styleForElement(documentEle ment()); |
1632 | 1647 |
1633 WritingMode rootWritingMode = documentElementStyle->writingMode(); | 1648 WritingMode rootWritingMode = documentElementStyle->writingMode(); |
1634 TextDirection rootDirection = documentElementStyle->direction(); | 1649 TextDirection rootDirection = documentElementStyle->direction(); |
1650 | |
1635 HTMLElement* body = this->body(); | 1651 HTMLElement* body = this->body(); |
1636 | 1652 RefPtr<RenderStyle> bodyStyle; |
1637 if (body) { | 1653 if (body) { |
1638 RefPtr<RenderStyle> bodyStyle = body->renderStyle(); | 1654 bodyStyle = body->renderStyle(); |
1639 if (!bodyStyle || body->needsStyleRecalc() || documentElement()->needsSt yleRecalc() || change == Force) | 1655 if (!bodyStyle || body->needsStyleRecalc() || documentElement()->needsSt yleRecalc() || change == Force) |
1640 bodyStyle = ensureStyleResolver().styleForElement(body, documentElem entStyle.get()); | 1656 bodyStyle = ensureStyleResolver().styleForElement(body, documentElem entStyle.get()); |
1641 if (!writingModeSetOnDocumentElement()) | 1657 if (!writingModeSetOnDocumentElement()) |
1642 rootWritingMode = bodyStyle->writingMode(); | 1658 rootWritingMode = bodyStyle->writingMode(); |
1643 if (!directionSetOnDocumentElement()) | 1659 if (!directionSetOnDocumentElement()) |
1644 rootDirection = bodyStyle->direction(); | 1660 rootDirection = bodyStyle->direction(); |
1645 } | 1661 } |
1646 | 1662 |
1663 RefPtr<RenderStyle> overflowStyle; | |
1664 if (Element* element = pickViewportDefiningElement(documentElement(), docume ntElementStyle.get(), body, bodyStyle.get())) { | |
1665 if (element == body) { | |
1666 overflowStyle = bodyStyle; | |
1667 } else { | |
1668 ASSERT(element == documentElement()); | |
1669 overflowStyle = documentElementStyle; | |
1670 } | |
1671 } | |
1672 | |
1647 // Resolved rem units are stored in the matched properties cache so we need to make sure to | 1673 // Resolved rem units are stored in the matched properties cache so we need to make sure to |
1648 // invalidate the cache if the documentElement needed to reattach or the fon t size changed | 1674 // invalidate the cache if the documentElement needed to reattach or the fon t size changed |
1649 // and then trigger a full document recalc. We also need to clear it here si nce the | 1675 // and then trigger a full document recalc. We also need to clear it here si nce the |
1650 // call to styleForElement on the body above can cache bad values for rem un its if the | 1676 // call to styleForElement on the body above can cache bad values for rem un its if the |
1651 // documentElement's style was dirty. We could keep track of which elements depend on | 1677 // documentElement's style was dirty. We could keep track of which elements depend on |
1652 // rem units like we do for viewport styles, but we assume root font size ch anges are | 1678 // rem units like we do for viewport styles, but we assume root font size ch anges are |
1653 // rare and just invalidate the cache for now. | 1679 // rare and just invalidate the cache for now. |
1654 if (styleEngine()->usesRemUnits() && (documentElement()->needsAttach() || do cumentElement()->computedStyle()->fontSize() != documentElementStyle->fontSize() )) { | 1680 if (styleEngine()->usesRemUnits() && (documentElement()->needsAttach() || do cumentElement()->computedStyle()->fontSize() != documentElementStyle->fontSize() )) { |
1655 ensureStyleResolver().invalidateMatchedPropertiesCache(); | 1681 ensureStyleResolver().invalidateMatchedPropertiesCache(); |
1656 documentElement()->setNeedsStyleRecalc(SubtreeStyleChange); | 1682 documentElement()->setNeedsStyleRecalc(SubtreeStyleChange); |
1657 } | 1683 } |
1658 | 1684 |
1659 RefPtr<RenderStyle> documentStyle = renderView()->style(); | 1685 RefPtr<RenderStyle> documentStyle = renderView()->style(); |
1660 if (documentStyle->writingMode() != rootWritingMode || documentStyle->direct ion() != rootDirection) { | 1686 if (documentStyle->writingMode() != rootWritingMode |
1687 || documentStyle->direction() != rootDirection | |
1688 || (overflowStyle && (documentStyle->overflowX() != overflowStyle->overf lowX() || documentStyle->overflowY() != overflowStyle->overflowY()))) { | |
1661 RefPtr<RenderStyle> newStyle = RenderStyle::clone(documentStyle.get()); | 1689 RefPtr<RenderStyle> newStyle = RenderStyle::clone(documentStyle.get()); |
1662 newStyle->setWritingMode(rootWritingMode); | 1690 newStyle->setWritingMode(rootWritingMode); |
1663 newStyle->setDirection(rootDirection); | 1691 newStyle->setDirection(rootDirection); |
1692 EOverflow overflowX = OAUTO; | |
1693 EOverflow overflowY = OAUTO; | |
1694 if (overflowStyle) { | |
1695 overflowX = overflowStyle->overflowX(); | |
1696 overflowY = overflowStyle->overflowY(); | |
1697 // Visible overflow on the viewport is meaningless. | |
1698 if (overflowX == OVISIBLE) | |
1699 overflowX = OAUTO; | |
ojan
2014/02/08 01:40:19
We need to do this because pagination doesn't work
mstensho (USE GERRIT)
2014/02/11 10:44:14
overflow:visible is meaningless on the viewport, r
| |
1700 if (overflowY == OVISIBLE) | |
1701 overflowY = OAUTO; | |
1702 | |
1703 // Column-gap is (ab)used by the current paged overflow implementati on (in lack of other | |
1704 // ways to specify gaps between pages), so we have to propagate it t oo. | |
1705 newStyle->setColumnGap(overflowStyle->columnGap()); | |
1706 } | |
1707 newStyle->setOverflowX(overflowX); | |
1708 newStyle->setOverflowY(overflowY); | |
1664 renderView()->setStyle(newStyle); | 1709 renderView()->setStyle(newStyle); |
1665 setStyleDependentState(newStyle.get()); | 1710 setStyleDependentState(newStyle.get()); |
1666 } | 1711 } |
1667 | 1712 |
1668 if (body) { | 1713 if (body) { |
1669 if (RenderStyle* style = body->renderStyle()) { | 1714 if (RenderStyle* style = body->renderStyle()) { |
1670 if (style->direction() != rootDirection || style->writingMode() != r ootWritingMode) | 1715 if (style->direction() != rootDirection || style->writingMode() != r ootWritingMode) |
1671 body->setNeedsStyleRecalc(SubtreeStyleChange); | 1716 body->setNeedsStyleRecalc(SubtreeStyleChange); |
1672 } | 1717 } |
1673 } | 1718 } |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2333 if (!de) | 2378 if (!de) |
2334 return 0; | 2379 return 0; |
2335 | 2380 |
2336 for (Node* node = de->firstChild(); node; node = node->nextSibling()) { | 2381 for (Node* node = de->firstChild(); node; node = node->nextSibling()) { |
2337 if (node->hasTagName(headTag)) | 2382 if (node->hasTagName(headTag)) |
2338 return toHTMLHeadElement(node); | 2383 return toHTMLHeadElement(node); |
2339 } | 2384 } |
2340 return 0; | 2385 return 0; |
2341 } | 2386 } |
2342 | 2387 |
2388 Element* Document::viewportDefiningElement() const | |
2389 { | |
2390 Element* rootElement = documentElement(); | |
2391 Element* bodyElement = body(); | |
2392 return pickViewportDefiningElement( | |
2393 rootElement, rootElement ? rootElement->renderStyle() : 0, | |
2394 bodyElement, bodyElement ? bodyElement->renderStyle() : 0); | |
2395 } | |
2396 | |
2343 void Document::close() | 2397 void Document::close() |
2344 { | 2398 { |
2345 // FIXME: We should follow the specification more closely: | 2399 // FIXME: We should follow the specification more closely: |
2346 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl ose | 2400 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl ose |
2347 | 2401 |
2348 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy Script() || !scriptableDocumentParser()->isParsing()) | 2402 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy Script() || !scriptableDocumentParser()->isParsing()) |
2349 return; | 2403 return; |
2350 | 2404 |
2351 explicitClose(); | 2405 explicitClose(); |
2352 } | 2406 } |
(...skipping 3045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5398 void Document::defaultEventHandler(Event* event) | 5452 void Document::defaultEventHandler(Event* event) |
5399 { | 5453 { |
5400 if (frame() && frame()->remotePlatformLayer()) { | 5454 if (frame() && frame()->remotePlatformLayer()) { |
5401 frame()->chromeClient().forwardInputEvent(this, event); | 5455 frame()->chromeClient().forwardInputEvent(this, event); |
5402 return; | 5456 return; |
5403 } | 5457 } |
5404 Node::defaultEventHandler(event); | 5458 Node::defaultEventHandler(event); |
5405 } | 5459 } |
5406 | 5460 |
5407 } // namespace WebCore | 5461 } // namespace WebCore |
OLD | NEW |