+2006-11-08 Anders Carlsson <acarlsson@apple.com>
+
+ Reviewed by Oliver.
+
+ Move methods from the bridge and frame into editor.
+
+ * WebCore.exp:
+ * bridge/EditorClient.h:
+ * bridge/mac/WebCoreFrameBridge.h:
+ * bridge/mac/WebCoreFrameBridge.mm:
+ * editing/Editor.cpp:
+ (WebCore::Editor::removeFormattingAndStyle):
+ (WebCore::Editor::applyStyle):
+ (WebCore::Editor::applyParagraphStyle):
+ (WebCore::Editor::applyStyleToSelection):
+ (WebCore::Editor::applyParagraphStyleToSelection):
+ (WebCore::Editor::toggleBold):
+ (WebCore::Editor::toggleItalic):
+ (WebCore::Editor::selectionStartHasStyle):
+ * editing/Editor.h:
+ * editing/JSEditor.cpp:
+ * page/Frame.cpp:
+ * page/Frame.h:
+
2006-11-08 Geoffrey Garen <ggaren@apple.com>
Reviewed by Beth.
__ZN7WebCore5Image21getTIFFRepresentationEv
__ZN7WebCore5RangeC1EPNS_8DocumentEPNS_4NodeEiS4_i
__ZN7WebCore5RangeD1Ev
+__ZN7WebCore6Editor10applyStyleEPNS_19CSSStyleDeclarationENS_10EditActionE
+__ZN7WebCore6Editor10toggleBoldEv
+__ZN7WebCore6Editor12toggleItalicEv
+__ZN7WebCore6Editor19applyParagraphStyleEPNS_19CSSStyleDeclarationENS_10EditActionE
+__ZN7WebCore6Editor21applyStyleToSelectionEPNS_19CSSStyleDeclarationENS_10EditActionE
+__ZNK7WebCore6Editor22selectionStartHasStyleEPNS_19CSSStyleDeclarationE
+__ZN7WebCore6Editor30applyParagraphStyleToSelectionEPNS_19CSSStyleDeclarationENS_10EditActionE
__ZN7WebCore6Editor30deleteSelectionWithSmartDeleteEb
__ZN7WebCore6StringC1EP8NSString
__ZN7WebCore6StringC1EPKc
namespace WebCore {
+class CSSStyleDeclaration;
class Range;
class HTMLElement;
// virtual bool shouldInsertNode(Node *node, Range* replacingRange, WebViewInsertAction givenAction) = 0;
// virtual bool shouldInsertText(NSString *text, Range *replacingRange, WebViewInsertAction givenAction) = 0;
// virtual bool shouldChangeSelectedRange(Range *currentRange, Range *toProposedRange, NSSelectionAffinity selectionAffinity, bool stillSelecting) = 0;
-// virtual bool shouldApplyStyle(CSSStyleDeclaration *style, Range *toElementsInDOMRange) = 0;
+ virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*) = 0;
// virtual bool shouldChangeTypingStyle(CSSStyleDeclaration *currentStyle, CSSStyleDeclaration *toProposedStyle) = 0;
// virtual bool doCommandBySelector(SEL selector) = 0;
//
- (DOMCSSStyleDeclaration *)typingStyle;
- (void)setTypingStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(WebCore::EditAction)undoAction;
-- (void)applyStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(WebCore::EditAction)undoAction;
-- (void)applyParagraphStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(WebCore::EditAction)undoAction;
-- (BOOL)selectionStartHasStyle:(DOMCSSStyleDeclaration *)style;
- (NSCellStateValue)selectionHasStyle:(DOMCSSStyleDeclaration *)style;
- (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)info;
m_frame->computeAndSetTypingStyle([style _CSSStyleDeclaration], undoAction);
}
-- (void)applyStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
-{
- if (!m_frame)
- return;
- m_frame->applyStyle([style _CSSStyleDeclaration], undoAction);
-}
-
-- (void)applyParagraphStyle:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
-{
- if (!m_frame)
- return;
- m_frame->applyParagraphStyle([style _CSSStyleDeclaration], undoAction);
-}
-
-- (BOOL)selectionStartHasStyle:(DOMCSSStyleDeclaration *)style
-{
- if (!m_frame)
- return NO;
- return m_frame->selectionStartHasStyle([style _CSSStyleDeclaration]);
-}
-
- (NSCellStateValue)selectionHasStyle:(DOMCSSStyleDeclaration *)style
{
if (!m_frame)
#include "ApplyStyleCommand.h"
#include "CSSComputedStyleDeclaration.h"
+#include "CSSProperty.h"
+#include "CSSPropertyNames.h"
#include "DeleteButtonController.h"
#include "DeleteSelectionCommand.h"
#include "Document.h"
void Editor::removeFormattingAndStyle()
{
- Document* document = frame()->document();
+ Document* document = m_frame->document();
// Make a plain text string from the selection to remove formatting like tables and lists.
- RefPtr<DocumentFragment> text = createFragmentFromText(frame()->selectionController()->toRange().get(), frame()->selectionController()->toString());
+ RefPtr<DocumentFragment> text = createFragmentFromText(m_frame->selectionController()->toRange().get(), m_frame->selectionController()->toString());
// Put the fragment made from that string into a style span with the document's
// default style to make sure that it is unstyled regardless of where it is inserted.
m_lastEditCommand = lastEditCommand;
}
+void Editor::applyStyle(CSSStyleDeclaration *style, EditAction editingAction)
+{
+ switch (m_frame->selectionController()->state()) {
+ case Selection::NONE:
+ // do nothing
+ break;
+ case Selection::CARET: {
+ m_frame->computeAndSetTypingStyle(style, editingAction);
+ break;
+ }
+ case Selection::RANGE:
+ if (m_frame->document() && style)
+ applyCommand(new ApplyStyleCommand(m_frame->document(), style, editingAction));
+ break;
+ }
+}
+
+void Editor::applyParagraphStyle(CSSStyleDeclaration *style, EditAction editingAction)
+{
+ switch (m_frame->selectionController()->state()) {
+ case Selection::NONE:
+ // do nothing
+ break;
+ case Selection::CARET:
+ case Selection::RANGE:
+ if (m_frame->document() && style)
+ applyCommand(new ApplyStyleCommand(m_frame->document(), style, editingAction, ApplyStyleCommand::ForceBlockProperties));
+ break;
+ }
+}
+
+void Editor::applyStyleToSelection(CSSStyleDeclaration* style, EditAction editingAction)
+{
+ if (!style || style->length() == 0 || !canEditRichly())
+ return;
+
+ if (m_client->shouldApplyStyle(style, m_frame->selectionController()->toRange().get()))
+ applyStyle(style, editingAction);
+}
+
+void Editor::applyParagraphStyleToSelection(CSSStyleDeclaration* style, EditAction editingAction)
+{
+ if (!style || style->length() == 0 || !canEditRichly())
+ return;
+
+ if (m_client->shouldApplyStyle(style, m_frame->selectionController()->toRange().get()))
+ applyParagraphStyle(style, editingAction);
+}
+
+void Editor::toggleBold()
+{
+ ExceptionCode ec;
+
+ RefPtr<CSSStyleDeclaration> style = m_frame->document()->createCSSStyleDeclaration();
+ style->setProperty(CSS_PROP_FONT_WEIGHT, "bold", false, ec);
+ if (selectionStartHasStyle(style.get()))
+ style->setProperty(CSS_PROP_FONT_WEIGHT, "normal", false, ec);
+ applyStyleToSelection(style.get(), EditActionSetFont);
+}
+
+void Editor::toggleItalic()
+{
+ ExceptionCode ec;
+
+ RefPtr<CSSStyleDeclaration> style = m_frame->document()->createCSSStyleDeclaration();
+ style->setProperty(CSS_PROP_FONT_STYLE, "italic", false, ec);
+ if (selectionStartHasStyle(style.get()))
+ style->setProperty(CSS_PROP_FONT_STYLE, "normal", false, ec);
+ applyStyleToSelection(style.get(), EditActionSetFont);
+}
+
+bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const
+{
+ Node* nodeToRemove;
+ RefPtr<CSSStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);
+ if (!selectionStyle)
+ return false;
+
+ RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
+
+ bool match = true;
+ DeprecatedValueListConstIterator<CSSProperty> end;
+ for (DeprecatedValueListConstIterator<CSSProperty> it = mutableStyle->valuesIterator(); it != end; ++it) {
+ int propertyID = (*it).id();
+ if (!equalIgnoringCase(mutableStyle->getPropertyValue(propertyID), selectionStyle->getPropertyValue(propertyID))) {
+ match = false;
+ break;
+ }
+ }
+
+ if (nodeToRemove) {
+ ExceptionCode ec = 0;
+ nodeToRemove->remove(ec);
+ assert(ec == 0);
+ }
+
+ return match;
+}
+
// =============================================================================
//
// public editing commands
void deleteSelectionWithSmartDelete(bool smartDelete);
+ void applyStyle(CSSStyleDeclaration*, EditAction = EditActionUnspecified);
+ void applyParagraphStyle(CSSStyleDeclaration*, EditAction = EditActionUnspecified);
+ void applyStyleToSelection(CSSStyleDeclaration*, EditAction);
+ void applyParagraphStyleToSelection(CSSStyleDeclaration*, EditAction);
+
+ void toggleBold();
+ void toggleItalic();
+
+ bool selectionStartHasStyle(CSSStyleDeclaration*) const;
private:
Frame* m_frame;
RefPtr<EditorClient> m_client;
{
RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
style->setProperty(propertyID, propertyValue);
- frame->applyStyle(style.get());
+ frame->editor()->applyStyle(style.get());
return true;
}
{
RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration;
style->setProperty(propertyID, desiredValue);
- return frame->selectionStartHasStyle(style.get());
+ return frame->editor()->selectionStartHasStyle(style.get());
}
String valueStyle(Frame* frame, int propertyID)
d->m_typingStyle = mutableStyle.release();
}
-void Frame::applyStyle(CSSStyleDeclaration *style, EditAction editingAction)
-{
- switch (selectionController()->state()) {
- case Selection::NONE:
- // do nothing
- break;
- case Selection::CARET: {
- computeAndSetTypingStyle(style, editingAction);
- break;
- }
- case Selection::RANGE:
- if (document() && style)
- applyCommand(new ApplyStyleCommand(document(), style, editingAction));
- break;
- }
-}
-
-void Frame::applyParagraphStyle(CSSStyleDeclaration *style, EditAction editingAction)
-{
- switch (selectionController()->state()) {
- case Selection::NONE:
- // do nothing
- break;
- case Selection::CARET:
- case Selection::RANGE:
- if (document() && style)
- applyCommand(new ApplyStyleCommand(document(), style, editingAction, ApplyStyleCommand::ForceBlockProperties));
- break;
- }
-}
-
void Frame::indent()
{
applyCommand(new IndentOutdentCommand(document(), IndentOutdentCommand::Indent));
return state;
}
-bool Frame::selectionStartHasStyle(CSSStyleDeclaration *style) const
-{
- Node* nodeToRemove;
- RefPtr<CSSStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
- if (!selectionStyle)
- return false;
-
- RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
-
- bool match = true;
- DeprecatedValueListConstIterator<CSSProperty> end;
- for (DeprecatedValueListConstIterator<CSSProperty> it = mutableStyle->valuesIterator(); it != end; ++it) {
- int propertyID = (*it).id();
- if (!equalIgnoringCase(mutableStyle->getPropertyValue(propertyID), selectionStyle->getPropertyValue(propertyID))) {
- match = false;
- break;
- }
- }
-
- if (nodeToRemove) {
- ExceptionCode ec = 0;
- nodeToRemove->remove(ec);
- assert(ec == 0);
- }
-
- return match;
-}
-
String Frame::selectionStartStylePropertyValue(int stylePropertyID) const
{
Node *nodeToRemove;
virtual bool canRedo() const = 0;
virtual bool canUndo() const = 0;
void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
- void applyStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
- void applyParagraphStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
void indent();
void outdent();
enum TriState { falseTriState, trueTriState, mixedTriState };
TriState selectionHasStyle(CSSStyleDeclaration*) const;
- bool selectionStartHasStyle(CSSStyleDeclaration*) const;
String selectionStartStylePropertyValue(int stylePropertyID) const;
void applyEditingStyleToBodyElement() const;
void removeEditingStyleFromBodyElement() const;
+2006-11-08 Anders Carlsson <acarlsson@apple.com>
+
+ Reviewed by Oliver.
+
+ Call into the WebCore editor object directly.
+
+ * MigrateHeaders.make:
+ * WebCoreSupport/WebEditorClient.h:
+ * WebCoreSupport/WebEditorClient.mm:
+ (WebEditorClient::shouldDeleteRange):
+ (WebEditorClient::shouldShowDeleteInterface):
+ (WebEditorClient::shouldApplyStyle):
+ * WebView/WebFrame.mm:
+ (core):
+ (kit):
+ * WebView/WebFrameInternal.h:
+ * WebView/WebHTMLView.m:
+ (-[NSArray _applyStyleToSelection:withUndoAction:]):
+ (-[NSArray _applyParagraphStyleToSelection:withUndoAction:]):
+ (-[NSArray _toggleBold]):
+ (-[NSArray _toggleItalic]):
+ (-[NSArray _changeCSSColorUsingSelector:inRange:]):
+ (-[NSArray underline:]):
+ (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]):
+ * WebView/WebView.mm:
+ (-[WebView applyStyle:]):
+
2006-11-08 Anders Carlsson <acarlsson@apple.com>
Reviewed by Oliver.
$(PUBLIC_HEADERS_DIR)/DOMCSSRule.h \
$(PUBLIC_HEADERS_DIR)/DOMCSSRuleList.h \
$(PUBLIC_HEADERS_DIR)/DOMCSSStyleDeclaration.h \
+ $(INTERNAL_HEADERS_DIR)/DOMCSSStyleDeclarationInternal.h \
$(PUBLIC_HEADERS_DIR)/DOMCSSStyleRule.h \
$(PUBLIC_HEADERS_DIR)/DOMCSSStyleSheet.h \
$(PUBLIC_HEADERS_DIR)/DOMCSSUnknownRule.h \
// bool shouldInsertNode(Node *node, Range* replacingRange, WebViewInsertAction givenAction);
// bool shouldInsertText(NSString *text, Range *replacingRange, WebViewInsertActiongivenAction);
// bool shouldChangeSelectedRange(Range *currentRange, Range *toProposedRange, NSSelectionAffinity selectionAffinity, bool stillSelecting);
-// bool shouldApplyStyle(CSSStyleDeclaration *style, Range *toElementsInDOMRange);
+ bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
// bool shouldChangeTypingStyle(CSSStyleDeclaration *currentStyle, CSSStyleDeclaration *toProposedStyle);
// bool doCommandBySelector(SEL selector);
#import "WebViewInternal.h"
#import "WebEditingDelegatePrivate.h"
+using namespace WebCore;
+
WebEditorClient::WebEditorClient()
: m_webView(nil)
{
return [m_webView spellCheckerDocumentTag];
}
-bool WebEditorClient::shouldDeleteRange(WebCore::Range* range)
+bool WebEditorClient::shouldDeleteRange(Range* range)
{
return [[m_webView _editingDelegateForwarder] webView:m_webView
shouldDeleteDOMRange:kit(range)];
}
-bool WebEditorClient::shouldShowDeleteInterface(WebCore::HTMLElement* element)
+bool WebEditorClient::shouldShowDeleteInterface(HTMLElement* element)
{
return [[m_webView _editingDelegateForwarder] webView:m_webView
shouldShowDeleteInterfaceForElement:kit(element)];
}
+bool WebEditorClient::shouldApplyStyle(CSSStyleDeclaration* style, Range* range)
+{
+ return [[m_webView _editingDelegateForwarder] webView:m_webView
+ shouldApplyStyle:kit(style) toElementsInDOMRange:kit(range)];
+}
+
/*
bool WebEditorClient::shouldBeginEditingInRange(Range *range) { return false; }
bool WebEditorClient::shouldEndEditingInRange(Range *range) { return false; }
bool WebEditorClient::shouldInsertNode(Node *node, Range* replacingRange, WebViewInsertAction givenAction) { return false; }
bool WebEditorClient::shouldInsertText(NSString *text, Range *replacingRange, WebViewInsertActiongivenAction) { return false; }
bool WebEditorClient::shouldChangeSelectedRange(Range *currentRange, Range *toProposedRange, NSSelectionAffinity selectionAffinity, bool stillSelecting) { return false; }
-bool WebEditorClient::shouldApplyStyle(CSSStyleDeclaration *style, Range *toElementsInDOMRange) { return false; }
bool WebEditorClient::shouldChangeTypingStyle(CSSStyleDeclaration *currentStyle, CSSStyleDeclaration *toProposedStyle) { return false; }
bool WebEditorClient::doCommandBySelector(SEL selector) { return false; }
#import "WebFrameInternal.h"
+#import "DOMCSSStyleDeclarationInternal.h"
#import "DOMDocumentInternal.h"
#import "DOMElementInternal.h"
#import "DOMHTMLElementInternal.h"
@end
+CSSStyleDeclaration* core(DOMCSSStyleDeclaration *declaration)
+{
+ return [declaration _CSSStyleDeclaration];
+}
+
+DOMCSSStyleDeclaration *kit(WebCore::CSSStyleDeclaration* declaration)
+{
+ return [DOMCSSStyleDeclaration _CSSStyleDeclarationWith:declaration];
+}
+
Element* core(DOMElement *element)
{
return [element _element];
#import <WebCore/FrameLoaderTypes.h>
#endif
+@class DOMCSSStyleDeclaration;
@class DOMElement;
@class DOMNode;
@class DOMRange;
#ifdef __cplusplus
namespace WebCore {
+ class CSSStyleDeclaration;
class Document;
class DocumentLoader;
class Element;
class Range;
}
+WebCore::CSSStyleDeclaration* core(DOMCSSStyleDeclaration *);
+DOMCSSStyleDeclaration *kit(WebCore::CSSStyleDeclaration*);
+
WebCore::FrameMac* core(WebFrame *);
WebFrame *kit(WebCore::Frame *);
- (void)_applyStyleToSelection:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
{
- if (style == nil || [style length] == 0 || ![self _canEditRichly])
- return;
- WebView *webView = [self _webView];
- WebFrameBridge *bridge = [self _bridge];
- if ([[webView _editingDelegateForwarder] webView:webView shouldApplyStyle:style toElementsInDOMRange:[self _selectedRange]]) {
- [bridge applyStyle:style withUndoAction:undoAction];
- }
+ Frame* coreFrame = core([self _frame]);
+ if (coreFrame)
+ coreFrame->editor()->applyStyleToSelection(core(style), undoAction);
}
- (void)_applyParagraphStyleToSelection:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
{
- if (style == nil || [style length] == 0 || ![self _canEditRichly])
- return;
- WebView *webView = [self _webView];
- WebFrameBridge *bridge = [self _bridge];
- if ([[webView _editingDelegateForwarder] webView:webView shouldApplyStyle:style toElementsInDOMRange:[self _selectedRange]])
- [bridge applyParagraphStyle:style withUndoAction:undoAction];
+ Frame* coreFrame = core([self _frame]);
+ if (coreFrame)
+ coreFrame->editor()->applyParagraphStyleToSelection(core(style), undoAction);
}
- (void)_toggleBold
{
- DOMCSSStyleDeclaration *style = [self _emptyStyle];
- [style setFontWeight:@"bold"];
- if ([[self _bridge] selectionStartHasStyle:style])
- [style setFontWeight:@"normal"];
- [self _applyStyleToSelection:style withUndoAction:EditActionSetFont];
+ Frame* coreFrame = core([self _frame]);
+ if (coreFrame)
+ coreFrame->editor()->toggleBold();
}
- (void)_toggleItalic
{
- DOMCSSStyleDeclaration *style = [self _emptyStyle];
- [style setFontStyle:@"italic"];
- if ([[self _bridge] selectionStartHasStyle:style])
- [style setFontStyle:@"normal"];
- [self _applyStyleToSelection:style withUndoAction:EditActionSetFont];
+ Frame* coreFrame = core([self _frame]);
+ if (coreFrame)
+ coreFrame->editor()->toggleItalic();
}
- (BOOL)_handleStyleKeyEquivalent:(NSEvent *)event
DOMCSSStyleDeclaration *style = [self _styleFromColorPanelWithSelector:selector];
WebView *webView = [self _webView];
if ([[webView _editingDelegateForwarder] webView:webView shouldApplyStyle:style toElementsInDOMRange:range])
- [[self _bridge] applyStyle:style withUndoAction:[self _undoActionFromColorPanelWithSelector:selector]];
+ core([self _frame])->editor()->applyStyle(core(style), [self _undoActionFromColorPanelWithSelector:selector]);
}
- (void)changeDocumentBackgroundColor:(id)sender
- (void)underline:(id)sender
{
+ Frame* coreFrame = core([self _frame]);
+ if (!coreFrame)
+ return;
// Despite the name, this method is actually supposed to toggle underline.
// FIXME: This currently clears overline, line-through, and blink as an unwanted side effect.
DOMCSSStyleDeclaration *style = [self _emptyStyle];
[style setProperty:@"-khtml-text-decorations-in-effect" value:@"underline" priority:@""];
- if ([[self _bridge] selectionStartHasStyle:style])
+ if (coreFrame->editor()->selectionStartHasStyle(core(style)))
[style setProperty:@"-khtml-text-decorations-in-effect" value:@"none" priority:@""];
[self _applyStyleToSelection:style withUndoAction:EditActionUnderline];
}
[[webView _UIDelegateForwarder] webView:webView
willPerformDragDestinationAction:WebDragDestinationActionEdit
forDraggingInfo:draggingInfo];
- [innerBridge applyStyle:style withUndoAction:EditActionSetColor];
+ coreFrame->editor()->applyStyle(core(style), EditActionSetColor);
return YES;
}
{
// We don't know enough at thls level to pass in a relevant WebUndoAction; we'd have to
// change the API to allow this.
- [[self _bridgeForSelectedOrMainFrame] applyStyle:style withUndoAction:EditActionUnspecified];
+ WebFrame *webFrame = [self _selectedOrMainFrame];
+ Frame* coreFrame = core(webFrame);
+ if (coreFrame)
+ coreFrame->editor()->applyStyle(core(style));
}
@end