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

Side by Side Diff: Source/core/editing/FrameSelection.cpp

Issue 25004008: Harden FrameSelection methods against JS running inside recalcStyle (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix build Created 7 years, 2 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 | « no previous file | Source/core/rendering/RenderView.cpp » ('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) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 if (m_selection.start().isNotNull() && m_selection.end().isNotNull()) { 1533 if (m_selection.start().isNotNull() && m_selection.end().isNotNull()) {
1534 if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache()) 1534 if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache())
1535 cache->selectionChanged(m_selection.start().containerNode()); 1535 cache->selectionChanged(m_selection.start().containerNode());
1536 } 1536 }
1537 } 1537 }
1538 1538
1539 void FrameSelection::focusedOrActiveStateChanged() 1539 void FrameSelection::focusedOrActiveStateChanged()
1540 { 1540 {
1541 bool activeAndFocused = isFocusedAndActive(); 1541 bool activeAndFocused = isFocusedAndActive();
1542 1542
1543 RefPtr<Document> document = m_frame->document();
1544 document->updateStyleIfNeeded();
1545
1543 // Because RenderObject::selectionBackgroundColor() and 1546 // Because RenderObject::selectionBackgroundColor() and
1544 // RenderObject::selectionForegroundColor() check if the frame is active, 1547 // RenderObject::selectionForegroundColor() check if the frame is active,
1545 // we have to update places those colors were painted. 1548 // we have to update places those colors were painted.
1546 if (RenderView* view = m_frame->document()->renderView()) 1549 if (RenderView* view = document->renderView())
1547 view->repaintSelection(); 1550 view->repaintSelection();
1548 1551
1549 // Caret appears in the active frame. 1552 // Caret appears in the active frame.
1550 if (activeAndFocused) 1553 if (activeAndFocused)
1551 setSelectionFromNone(); 1554 setSelectionFromNone();
1552 else 1555 else
1553 m_frame->spellChecker().spellCheckAfterBlur(); 1556 m_frame->spellChecker().spellCheckAfterBlur();
1554 setCaretVisibility(activeAndFocused ? Visible : Hidden); 1557 setCaretVisibility(activeAndFocused ? Visible : Hidden);
1555 1558
1556 // Update for caps lock state 1559 // Update for caps lock state
1557 m_frame->eventHandler()->capsLockStateMayHaveChanged(); 1560 m_frame->eventHandler()->capsLockStateMayHaveChanged();
1558 1561
1559 // Because StyleResolver::checkOneSelector() and 1562 // Because StyleResolver::checkOneSelector() and
1560 // RenderTheme::isFocused() check if the frame is active, we have to 1563 // RenderTheme::isFocused() check if the frame is active, we have to
1561 // update style and theme state that depended on those. 1564 // update style and theme state that depended on those.
1562 if (Element* element = m_frame->document()->focusedElement()) { 1565 if (Element* element = document->focusedElement()) {
1563 element->setNeedsStyleRecalc(); 1566 element->setNeedsStyleRecalc();
1564 if (RenderObject* renderer = element->renderer()) { 1567 if (RenderObject* renderer = element->renderer()) {
1565 if (renderer && renderer->style()->hasAppearance()) 1568 if (renderer && renderer->style()->hasAppearance())
1566 RenderTheme::theme().stateChanged(renderer, FocusState); 1569 RenderTheme::theme().stateChanged(renderer, FocusState);
1567 } 1570 }
1568 } 1571 }
1569 1572
1570 // Secure keyboard entry is set by the active frame. 1573 // Secure keyboard entry is set by the active frame.
1571 if (m_frame->document()->useSecureKeyboardEntryWhenActive()) 1574 if (document->useSecureKeyboardEntryWhenActive())
1572 setUseSecureKeyboardEntry(activeAndFocused); 1575 setUseSecureKeyboardEntry(activeAndFocused);
1573 } 1576 }
1574 1577
1575 void FrameSelection::pageActivationChanged() 1578 void FrameSelection::pageActivationChanged()
1576 { 1579 {
1577 focusedOrActiveStateChanged(); 1580 focusedOrActiveStateChanged();
1578 } 1581 }
1579 1582
1580 void FrameSelection::updateSecureKeyboardEntryIfActive() 1583 void FrameSelection::updateSecureKeyboardEntryIfActive()
1581 { 1584 {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 1801
1799 String FrameSelection::selectedTextForClipboard() const 1802 String FrameSelection::selectedTextForClipboard() const
1800 { 1803 {
1801 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex t()) 1804 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex t())
1802 return extractSelectedText(*this, TextIteratorEmitsImageAltText); 1805 return extractSelectedText(*this, TextIteratorEmitsImageAltText);
1803 return selectedText(); 1806 return selectedText();
1804 } 1807 }
1805 1808
1806 FloatRect FrameSelection::bounds(bool clipToVisibleContent) const 1809 FloatRect FrameSelection::bounds(bool clipToVisibleContent) const
1807 { 1810 {
1808 RenderView* root = m_frame->contentRenderer(); 1811 m_frame->document()->updateStyleIfNeeded();
1812
1809 FrameView* view = m_frame->view(); 1813 FrameView* view = m_frame->view();
1810 if (!root || !view) 1814 RenderView* renderView = m_frame->contentRenderer();
1811 return LayoutRect();
1812 1815
1813 LayoutRect selectionRect = root->selectionBounds(clipToVisibleContent); 1816 if (!view || !renderView)
1817 return FloatRect();
1818
1819 LayoutRect selectionRect = renderView->selectionBounds(clipToVisibleContent) ;
1814 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte ntRect()) : selectionRect; 1820 return clipToVisibleContent ? intersection(selectionRect, view->visibleConte ntRect()) : selectionRect;
1815 } 1821 }
1816 1822
1817 void FrameSelection::getClippedVisibleTextRectangles(Vector<FloatRect>& rectangl es) const 1823 void FrameSelection::getClippedVisibleTextRectangles(Vector<FloatRect>& rectangl es) const
1818 { 1824 {
1819 RenderView* root = m_frame->contentRenderer(); 1825 RenderView* root = m_frame->contentRenderer();
1820 if (!root) 1826 if (!root)
1821 return; 1827 return;
1822 1828
1823 FloatRect visibleContentRect = m_frame->view()->visibleContentRect(); 1829 FloatRect visibleContentRect = m_frame->view()->visibleContentRect();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 sel.showTreeForThis(); 1970 sel.showTreeForThis();
1965 } 1971 }
1966 1972
1967 void showTree(const WebCore::FrameSelection* sel) 1973 void showTree(const WebCore::FrameSelection* sel)
1968 { 1974 {
1969 if (sel) 1975 if (sel)
1970 sel->showTreeForThis(); 1976 sel->showTreeForThis();
1971 } 1977 }
1972 1978
1973 #endif 1979 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/rendering/RenderView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698