- Revision
- 97585
- Author
- rn...@webkit.org
- Date
- 2011-10-16 22:44:50 -0700 (Sun, 16 Oct 2011)
Log Message
[Mac] fontForSelection and styleForSelectionStart should be moved to EditorMac
https://bugs.webkit.org/show_bug.cgi?id=70114
Reviewed by Hajime Morita.
Moved fontForSelection and styleForSelectionStart from Editor to EditorMac
and made styleForSelectionStart static local.
* editing/Editor.cpp:
* editing/Editor.h:
* editing/mac/EditorMac.mm:
(WebCore::styleForSelectionStart):
(WebCore::Editor::fontForSelection):
(WebCore::Editor::fontAttributesForSelectionStart):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (97584 => 97585)
--- trunk/Source/WebCore/ChangeLog 2011-10-17 05:06:15 UTC (rev 97584)
+++ trunk/Source/WebCore/ChangeLog 2011-10-17 05:44:50 UTC (rev 97585)
@@ -1,3 +1,20 @@
+2011-10-16 Ryosuke Niwa <rn...@webkit.org>
+
+ [Mac] fontForSelection and styleForSelectionStart should be moved to EditorMac
+ https://bugs.webkit.org/show_bug.cgi?id=70114
+
+ Reviewed by Hajime Morita.
+
+ Moved fontForSelection and styleForSelectionStart from Editor to EditorMac
+ and made styleForSelectionStart static local.
+
+ * editing/Editor.cpp:
+ * editing/Editor.h:
+ * editing/mac/EditorMac.mm:
+ (WebCore::styleForSelectionStart):
+ (WebCore::Editor::fontForSelection):
+ (WebCore::Editor::fontAttributesForSelectionStart):
+
2011-10-16 Kentaro Hara <hara...@chromium.org>
Generate EventSource constructor for JSC by [Constructor] IDL
Modified: trunk/Source/WebCore/editing/Editor.cpp (97584 => 97585)
--- trunk/Source/WebCore/editing/Editor.cpp 2011-10-17 05:06:15 UTC (rev 97584)
+++ trunk/Source/WebCore/editing/Editor.cpp 2011-10-17 05:44:50 UTC (rev 97585)
@@ -509,53 +509,6 @@
client()->respondToChangedContents();
}
-#if PLATFORM(MAC)
-const SimpleFontData* Editor::fontForSelection(bool& hasMultipleFonts) const
-{
- hasMultipleFonts = false;
-
- if (!m_frame->selection()->isRange()) {
- Node* nodeToRemove;
- RenderStyle* style = styleForSelectionStart(nodeToRemove); // sets nodeToRemove
-
- const SimpleFontData* result = 0;
- if (style)
- result = style->font().primaryFont();
-
- if (nodeToRemove) {
- ExceptionCode ec;
- nodeToRemove->remove(ec);
- ASSERT(!ec);
- }
-
- return result;
- }
-
- const SimpleFontData* font = 0;
- RefPtr<Range> range = m_frame->selection()->toNormalizedRange();
- if (Node* startNode = adjustedSelectionStartForStyleComputation(m_frame->selection()->selection()).deprecatedNode()) {
- Node* pastEnd = range->pastLastNode();
- // In the loop below, n should eventually match pastEnd and not become nil, but we've seen at least one
- // unreproducible case where this didn't happen, so check for null also.
- for (Node* n = startNode; n && n != pastEnd; n = n->traverseNextNode()) {
- RenderObject* renderer = n->renderer();
- if (!renderer)
- continue;
- // FIXME: Are there any node types that have renderers, but that we should be skipping?
- const SimpleFontData* f = renderer->style()->font().primaryFont();
- if (!font)
- font = f;
- else if (font != f) {
- hasMultipleFonts = true;
- break;
- }
- }
- }
-
- return font;
-}
-#endif
-
WritingDirection Editor::textDirectionForSelection(bool& hasNestedOrMultipleEmbeddings) const
{
hasNestedOrMultipleEmbeddings = true;
@@ -2796,42 +2749,6 @@
ASSERT(!ec);
}
-#if PLATFORM(MAC)
-RenderStyle* Editor::styleForSelectionStart(Node *&nodeToRemove) const
-{
- nodeToRemove = 0;
-
- if (m_frame->selection()->isNone())
- return 0;
-
- Position position = m_frame->selection()->selection().visibleStart().deepEquivalent();
- if (!position.isCandidate())
- return 0;
- if (!position.deprecatedNode())
- return 0;
-
- RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle();
- if (!typingStyle || !typingStyle->style())
- return position.deprecatedNode()->renderer()->style();
-
- RefPtr<Element> styleElement = m_frame->document()->createElement(spanTag, false);
-
- ExceptionCode ec = 0;
- String styleText = typingStyle->style()->cssText() + " display: inline";
- styleElement->setAttribute(styleAttr, styleText.impl(), ec);
- ASSERT(!ec);
-
- styleElement->appendChild(m_frame->document()->createEditingTextNode(""), ec);
- ASSERT(!ec);
-
- position.deprecatedNode()->parentNode()->appendChild(styleElement, ec);
- ASSERT(!ec);
-
- nodeToRemove = styleElement.get();
- return styleElement->renderer() ? styleElement->renderer()->style() : 0;
-}
-#endif
-
// Searches from the beginning of the document if nothing is selected.
bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection)
{
Modified: trunk/Source/WebCore/editing/Editor.h (97584 => 97585)
--- trunk/Source/WebCore/editing/Editor.h 2011-10-17 05:06:15 UTC (rev 97584)
+++ trunk/Source/WebCore/editing/Editor.h 2011-10-17 05:44:50 UTC (rev 97585)
@@ -134,9 +134,6 @@
bool selectionStartHasStyle(int propertyID, const String& value) const;
TriState selectionHasStyle(int propertyID, const String& value) const;
String selectionStartCSSPropertyValue(int propertyID);
-#if PLATFORM(MAC)
- const SimpleFontData* fontForSelection(bool&) const;
-#endif
WritingDirection textDirectionForSelection(bool&) const;
TriState selectionUnorderedListState() const;
@@ -350,9 +347,6 @@
void respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions);
bool shouldChangeSelection(const VisibleSelection& oldSelection, const VisibleSelection& newSelection, EAffinity, bool stillSelecting) const;
-#if PLATFORM(MAC)
- RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
-#endif
unsigned countMatchesForText(const String&, FindOptions, unsigned limit, bool markMatches);
unsigned countMatchesForText(const String&, Range*, FindOptions, unsigned limit, bool markMatches);
bool markedTextMatchesAreHighlighted() const;
@@ -366,6 +360,7 @@
void textDidChangeInTextArea(Element*);
#if PLATFORM(MAC)
+ const SimpleFontData* fontForSelection(bool&) const;
NSDictionary* fontAttributesForSelectionStart() const;
NSWritingDirection baseWritingDirectionForSelectionStart() const;
bool canCopyExcludingStandaloneImages();
Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (97584 => 97585)
--- trunk/Source/WebCore/editing/mac/EditorMac.mm 2011-10-17 05:06:15 UTC (rev 97584)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm 2011-10-17 05:44:50 UTC (rev 97585)
@@ -30,17 +30,22 @@
#import "ClipboardMac.h"
#import "CachedResourceLoader.h"
#import "DocumentFragment.h"
+#import "EditingText.h"
#import "Editor.h"
#import "EditorClient.h"
#import "Frame.h"
#import "FrameView.h"
+#import "HTMLNames.h"
#import "Pasteboard.h"
#import "RenderBlock.h"
#import "RuntimeApplicationChecks.h"
#import "Sound.h"
+#import "htmlediting.h"
namespace WebCore {
+using namespace HTMLNames;
+
PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy, Frame* frame)
{
return ClipboardMac::create(Clipboard::CopyAndPaste, [NSPasteboard generalPasteboard], policy, frame);
@@ -89,10 +94,87 @@
m_frame->editor()->client()->setInsertionPasteboard(nil);
}
+static RenderStyle* styleForSelectionStart(Frame* frame, Node *&nodeToRemove)
+{
+ nodeToRemove = 0;
+
+ if (frame->selection()->isNone())
+ return 0;
+
+ Position position = frame->selection()->selection().visibleStart().deepEquivalent();
+ if (!position.isCandidate() || position.isNull())
+ return 0;
+
+ RefPtr<EditingStyle> typingStyle = frame->selection()->typingStyle();
+ if (!typingStyle || !typingStyle->style())
+ return position.deprecatedNode()->renderer()->style();
+
+ RefPtr<Element> styleElement = frame->document()->createElement(spanTag, false);
+
+ ExceptionCode ec = 0;
+ String styleText = typingStyle->style()->cssText() + " display: inline";
+ styleElement->setAttribute(styleAttr, styleText.impl(), ec);
+ ASSERT(!ec);
+
+ styleElement->appendChild(frame->document()->createEditingTextNode(""), ec);
+ ASSERT(!ec);
+
+ position.deprecatedNode()->parentNode()->appendChild(styleElement, ec);
+ ASSERT(!ec);
+
+ nodeToRemove = styleElement.get();
+ return styleElement->renderer() ? styleElement->renderer()->style() : 0;
+}
+
+const SimpleFontData* Editor::fontForSelection(bool& hasMultipleFonts) const
+{
+ hasMultipleFonts = false;
+
+ if (!m_frame->selection()->isRange()) {
+ Node* nodeToRemove;
+ RenderStyle* style = styleForSelectionStart(m_frame, nodeToRemove); // sets nodeToRemove
+
+ const SimpleFontData* result = 0;
+ if (style)
+ result = style->font().primaryFont();
+
+ if (nodeToRemove) {
+ ExceptionCode ec;
+ nodeToRemove->remove(ec);
+ ASSERT(!ec);
+ }
+
+ return result;
+ }
+
+ const SimpleFontData* font = 0;
+ RefPtr<Range> range = m_frame->selection()->toNormalizedRange();
+ if (Node* startNode = adjustedSelectionStartForStyleComputation(m_frame->selection()->selection()).deprecatedNode()) {
+ Node* pastEnd = range->pastLastNode();
+ // In the loop below, n should eventually match pastEnd and not become nil, but we've seen at least one
+ // unreproducible case where this didn't happen, so check for null also.
+ for (Node* node = startNode; node && node != pastEnd; node = node->traverseNextNode()) {
+ RenderObject* renderer = node->renderer();
+ if (!renderer)
+ continue;
+ // FIXME: Are there any node types that have renderers, but that we should be skipping?
+ const SimpleFontData* primaryFont = renderer->style()->font().primaryFont();
+ if (!font)
+ font = primaryFont;
+ else if (font != primaryFont) {
+ hasMultipleFonts = true;
+ break;
+ }
+ }
+ }
+
+ return font;
+}
+
NSDictionary* Editor::fontAttributesForSelectionStart() const
{
Node* nodeToRemove;
- RenderStyle* style = styleForSelectionStart(nodeToRemove);
+ RenderStyle* style = styleForSelectionStart(m_frame, nodeToRemove);
if (!style)
return nil;