Commit f9c8d307 authored by rniwa@webkit.org's avatar rniwa@webkit.org

2011-03-07 Ryosuke Niwa <rniwa@webkit.org>

        Reviewed by Darin Adler.

        selectionHasStyle and selectionStartHasStyle should use EditingStyle
        https://bugs.webkit.org/show_bug.cgi?id=55902

        selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.

        * src/ContextMenuClientImpl.cpp:
        (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems): Calls selectionHasStyle.
2011-03-07  Ryosuke Niwa  <rniwa@webkit.org>

        Reviewed by Darin Adler.

        selectionHasStyle and selectionStartHasStyle should use EditingStyle
        https://bugs.webkit.org/show_bug.cgi?id=55902

        selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.

        * WebView/WebHTMLView.mm: Removed unused selectionHasStyle.
        (-[WebHTMLView validateUserInterfaceItemWithoutDelegate:]): Calls Editor::selectionHasStyle.
2011-03-07  Ryosuke Niwa  <rniwa@webkit.org>

        Reviewed by Darin Adler.

        selectionHasStyle and selectionStartHasStyle should use EditingStyle
        https://bugs.webkit.org/show_bug.cgi?id=55902

        Deployed EditingStyle in selectionHasStyle and selectionStartHasStyle.
        This allowed us to move triStateOfStyle from Editor.cpp to EditingStyle.cpp.

        Also changed the argument lists of selectionHasStyle and selectionStartHasStyle
        to take a property id and a value instead of a CSSMutableStyleDeclaration to cleanup
        call sites of these two functions.

        * WebCore.exp.in: Updated the signature of selectionHasStyle. No longer exports
        selectionStartHasStyle because it's not called anywhere outside of WebCore.
        * WebCore.order: Ditto.
        * editing/EditingStyle.cpp:
        (WebCore::EditingStyle::EditingStyle): Added a new constructor that takes a property id
        and a property value.
        (WebCore::EditingStyle::triStateOfStyle): Moved from Editor.cpp.
        * editing/EditingStyle.h:
        (WebCore::EditingStyle::create): Added.
        * editing/Editor.cpp:
        (WebCore::Editor::selectionStartHasStyle): Takes a property id and a value instead of
        a CSSStyleDeclaration.
        (WebCore::Editor::selectionHasStyle): Ditto.
        * editing/Editor.h: Updated the signatures of selectionStartHasStyle and selectionHasStyle.
        * editing/EditorCommand.cpp:
        (WebCore::executeToggleStyle): Calls selectionStartHasStyle and selectionHasStyle.
        (WebCore::stateStyle): Ditto.
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::checkOrEnableIfNeeded): Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@80528 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b48cbe16
2011-03-07 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Darin Adler.
selectionHasStyle and selectionStartHasStyle should use EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=55902
Deployed EditingStyle in selectionHasStyle and selectionStartHasStyle.
This allowed us to move triStateOfStyle from Editor.cpp to EditingStyle.cpp.
Also changed the argument lists of selectionHasStyle and selectionStartHasStyle
to take a property id and a value instead of a CSSMutableStyleDeclaration to cleanup
call sites of these two functions.
* WebCore.exp.in: Updated the signature of selectionHasStyle. No longer exports
selectionStartHasStyle because it's not called anywhere outside of WebCore.
* WebCore.order: Ditto.
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::EditingStyle): Added a new constructor that takes a property id
and a property value.
(WebCore::EditingStyle::triStateOfStyle): Moved from Editor.cpp.
* editing/EditingStyle.h:
(WebCore::EditingStyle::create): Added.
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle): Takes a property id and a value instead of
a CSSStyleDeclaration.
(WebCore::Editor::selectionHasStyle): Ditto.
* editing/Editor.h: Updated the signatures of selectionStartHasStyle and selectionHasStyle.
* editing/EditorCommand.cpp:
(WebCore::executeToggleStyle): Calls selectionStartHasStyle and selectionHasStyle.
(WebCore::stateStyle): Ditto.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::checkOrEnableIfNeeded): Ditto.
2011-03-07 Alexey Proskuryakov <ap@apple.com>
Reviewed by Darin Adler.
......
......@@ -1195,9 +1195,8 @@ __ZNK7WebCore6Editor13canEditRichlyEv
__ZNK7WebCore6Editor16compositionRangeEv
__ZNK7WebCore6Editor16fontForSelectionERb
__ZNK7WebCore6Editor17firstRectForRangeEPNS_5RangeE
__ZNK7WebCore6Editor17selectionHasStyleEPNS_19CSSStyleDeclarationE
__ZNK7WebCore6Editor17selectionHasStyleEiRKN3WTF6StringE
__ZNK7WebCore6Editor17shouldDeleteRangeEPNS_5RangeE
__ZNK7WebCore6Editor22selectionStartHasStyleEPNS_19CSSStyleDeclarationE
__ZNK7WebCore6Editor23getCompositionSelectionERjS1_
__ZNK7WebCore6Editor30applyEditingStyleToBodyElementEv
__ZNK7WebCore6Editor31fontAttributesForSelectionStartEv
......
......@@ -286,6 +286,14 @@ EditingStyle::EditingStyle(const CSSStyleDeclaration* style)
extractFontSizeDelta();
}
EditingStyle::EditingStyle(int propertyID, const String& value)
: m_mutableStyle(0)
, m_shouldUseFixedDefaultFontSize(false)
, m_fontSizeDelta(NoFontDelta)
{
setProperty(propertyID, value);
}
EditingStyle::~EditingStyle()
{
}
......@@ -505,6 +513,30 @@ void EditingStyle::collapseTextDecorationProperties()
m_mutableStyle->removeProperty(CSSPropertyWebkitTextDecorationsInEffect);
}
// CSS properties that create a visual difference only when applied to text.
static const int textOnlyProperties[] = {
CSSPropertyTextDecoration,
CSSPropertyWebkitTextDecorationsInEffect,
CSSPropertyFontStyle,
CSSPropertyFontWeight,
CSSPropertyColor,
};
TriState EditingStyle::triStateOfStyle(CSSStyleDeclaration* styleToCompare, ShouldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const
{
RefPtr<CSSMutableStyleDeclaration> difference = getPropertiesNotIn(m_mutableStyle.get(), styleToCompare);
if (shouldIgnoreTextOnlyProperties == IgnoreTextOnlyProperties)
difference->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(textOnlyProperties));
if (!difference->length())
return TrueTriState;
if (difference->length() == m_mutableStyle->length())
return FalseTriState;
return MixedTriState;
}
bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement* element, EditingStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const
{
ASSERT(element);
......
......@@ -51,6 +51,8 @@ class QualifiedName;
class RenderStyle;
class StyledElement;
enum TriState { FalseTriState, TrueTriState, MixedTriState };
class EditingStyle : public RefCounted<EditingStyle> {
public:
......@@ -79,6 +81,11 @@ public:
return adoptRef(new EditingStyle(style));
}
static PassRefPtr<EditingStyle> create(int propertyID, const String& value)
{
return adoptRef(new EditingStyle(propertyID, value));
}
~EditingStyle();
CSSMutableStyleDeclaration* style() { return m_mutableStyle.get(); }
......@@ -95,6 +102,8 @@ public:
void removeStyleConflictingWithStyleOfNode(Node*);
void removeNonEditingProperties();
void collapseTextDecorationProperties();
enum ShouldIgnoreTextOnlyProperties { IgnoreTextOnlyProperties, DoNotIgnoreTextOnlyProperties };
TriState triStateOfStyle(CSSStyleDeclaration*, ShouldIgnoreTextOnlyProperties = DoNotIgnoreTextOnlyProperties) const;
bool conflictsWithInlineStyleOfElement(StyledElement* element) const { return conflictsWithInlineStyleOfElement(element, 0, 0); }
bool conflictsWithInlineStyleOfElement(StyledElement* element, EditingStyle* extractedStyle, Vector<CSSPropertyID>& conflictingProperties) const
{
......@@ -117,6 +126,7 @@ private:
EditingStyle(Node*, PropertiesToInclude);
EditingStyle(const Position&);
EditingStyle(const CSSStyleDeclaration*);
EditingStyle(int propertyID, const String& value);
void init(Node*, PropertiesToInclude);
void removeTextFillAndStrokeColorsIfNeeded(RenderStyle*);
void setProperty(int propertyID, const String& value, bool important = false);
......
......@@ -945,39 +945,18 @@ void Editor::applyParagraphStyleToSelection(CSSStyleDeclaration* style, EditActi
applyParagraphStyle(style, editingAction);
}
// CSS properties that only has a visual difference when applied to text.
static const int textOnlyProperties[] = {
CSSPropertyTextDecoration,
CSSPropertyWebkitTextDecorationsInEffect,
CSSPropertyFontStyle,
CSSPropertyFontWeight,
CSSPropertyColor,
};
static TriState triStateOfStyle(CSSStyleDeclaration* desiredStyle, CSSStyleDeclaration* styleToCompare, bool ignoreTextOnlyProperties = false)
{
RefPtr<CSSMutableStyleDeclaration> diff = getPropertiesNotIn(desiredStyle, styleToCompare);
if (ignoreTextOnlyProperties)
diff->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(textOnlyProperties));
if (!diff->length())
return TrueTriState;
if (diff->length() == desiredStyle->length())
return FalseTriState;
return MixedTriState;
}
bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const
bool Editor::selectionStartHasStyle(int propertyID, const String& value) const
{
RefPtr<EditingStyle> style = EditingStyle::create(propertyID, value);
RefPtr<EditingStyle> selectionStyle = selectionStartStyle();
if (!selectionStyle || !selectionStyle->style())
return false;
return triStateOfStyle(style, selectionStyle->style()) == TrueTriState;
return style->triStateOfStyle(selectionStyle->style()) == TrueTriState;
}
TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const
TriState Editor::selectionHasStyle(int propertyID, const String& value) const
{
RefPtr<EditingStyle> style = EditingStyle::create(propertyID, value);
if (!m_frame->selection()->isCaretOrRange())
return FalseTriState;
......@@ -985,14 +964,14 @@ TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const
RefPtr<EditingStyle> selectionStyle = selectionStartStyle();
if (!selectionStyle || !selectionStyle->style())
return FalseTriState;
return triStateOfStyle(style, selectionStyle->style());
return style->triStateOfStyle(selectionStyle->style());
}
TriState state = FalseTriState;
for (Node* node = m_frame->selection()->start().deprecatedNode(); node; node = node->traverseNextNode()) {
RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node);
if (nodeStyle) {
TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode());
TriState nodeState = style->triStateOfStyle(nodeStyle.get(), node->isTextNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTextOnlyProperties);
if (node == m_frame->selection()->start().deprecatedNode())
state = nodeState;
else if (state != nodeState && node->isTextNode()) {
......
......@@ -76,7 +76,6 @@ struct CompositionUnderline {
bool thick;
};
enum TriState { FalseTriState, TrueTriState, MixedTriState };
enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
class Editor {
......@@ -133,7 +132,8 @@ public:
void respondToChangedSelection(const VisibleSelection& oldSelection);
void respondToChangedContents(const VisibleSelection& endingSelection);
TriState selectionHasStyle(CSSStyleDeclaration*) const;
bool selectionStartHasStyle(int propertyID, const String& value) const;
TriState selectionHasStyle(int propertyID, const String& value) const;
String selectionStartCSSPropertyValue(int propertyID);
const SimpleFontData* fontForSelection(bool&) const;
WritingDirection textDirectionForSelection(bool&) const;
......@@ -170,8 +170,6 @@ public:
void reappliedEditing(PassRefPtr<EditCommand>);
void unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction);
bool selectionStartHasStyle(CSSStyleDeclaration*) const;
void setShouldStyleWithCSS(bool flag) { m_shouldStyleWithCSS = flag; }
bool shouldStyleWithCSS() const { return m_shouldStyleWithCSS; }
......
......@@ -156,21 +156,18 @@ static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, E
static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const char* offValue, const char* onValue)
{
RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
style->setProperty(propertyID, onValue); // We need to add this style to pass it to selectionStartHasStyle / selectionHasStyle
// Style is considered present when
// Mac: present at the beginning of selection
// other: present throughout the selection
bool styleIsPresent;
if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
styleIsPresent = frame->editor()->selectionStartHasStyle(style.get());
styleIsPresent = frame->editor()->selectionStartHasStyle(propertyID, onValue);
else
styleIsPresent = frame->editor()->selectionHasStyle(style.get()) == TrueTriState;
styleIsPresent = frame->editor()->selectionHasStyle(propertyID, onValue) == TrueTriState;
style->setProperty(propertyID, styleIsPresent ? offValue : onValue);
return applyCommandToFrame(frame, source, action, style.get());
RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
return applyCommandToFrame(frame, source, action, style->style());
}
static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const String& propertyValue)
......@@ -227,12 +224,9 @@ static bool expandSelectionToGranularity(Frame* frame, TextGranularity granulari
static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValue)
{
RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
style->setProperty(propertyID, desiredValue);
if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
return frame->editor()->selectionStartHasStyle(style.get()) ? TrueTriState : FalseTriState;
return frame->editor()->selectionHasStyle(style.get());
return frame->editor()->selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState;
return frame->editor()->selectionHasStyle(propertyID, desiredValue);
}
static String valueStyle(Frame* frame, int propertyID)
......
......@@ -1010,11 +1010,8 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
break;
case ContextMenuItemTagLeftToRight:
case ContextMenuItemTagRightToLeft: {
ExceptionCode ec = 0;
RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl";
style->setProperty(CSSPropertyDirection, direction, false, ec);
shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyDirection, direction) != FalseTriState;
shouldEnable = true;
break;
}
......@@ -1060,10 +1057,7 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
break;
#endif
case ContextMenuItemTagUnderline: {
ExceptionCode ec = 0;
RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
style->setProperty(CSSPropertyWebkitTextDecorationsInEffect, "underline", false, ec);
shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline") != FalseTriState;
shouldEnable = frame->editor()->canEditRichly();
break;
}
......@@ -1078,18 +1072,12 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
#endif
break;
case ContextMenuItemTagItalic: {
ExceptionCode ec = 0;
RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
style->setProperty(CSSPropertyFontStyle, "italic", false, ec);
shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic") != FalseTriState;
shouldEnable = frame->editor()->canEditRichly();
break;
}
case ContextMenuItemTagBold: {
ExceptionCode ec = 0;
RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
style->setProperty(CSSPropertyFontWeight, "bold", false, ec);
shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold") != FalseTriState;
shouldEnable = frame->editor()->canEditRichly();
break;
}
......
2011-03-07 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Darin Adler.
selectionHasStyle and selectionStartHasStyle should use EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=55902
selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.
* src/ContextMenuClientImpl.cpp:
(WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems): Calls selectionHasStyle.
2011-03-07 Daniel Cheng <dcheng@chromium.org>
Reviewed by Tony Chang.
......
......@@ -262,13 +262,9 @@ PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems(
}
#if OS(DARWIN)
ExceptionCode ec = 0;
RefPtr<CSSStyleDeclaration> style = selectedFrame->document()->createCSSStyleDeclaration();
style->setProperty(CSSPropertyDirection, "ltr", false, ec);
if (selectedFrame->editor()->selectionHasStyle(style.get()) != FalseTriState)
if (selectedFrame->editor()->selectionHasStyle(CSSPropertyDirection, 'ltr') != FalseTriState)
data.writingDirectionLeftToRight |= WebContextMenuData::CheckableMenuItemChecked;
style->setProperty(CSSPropertyDirection, "rtl", false, ec);
if (selectedFrame->editor()->selectionHasStyle(style.get()) != FalseTriState)
if (selectedFrame->editor()->selectionHasStyle(CSSPropertyDirection, 'rtl') != FalseTriState)
data.writingDirectionRightToLeft |= WebContextMenuData::CheckableMenuItemChecked;
#endif // OS(DARWIN)
......
2011-03-07 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Darin Adler.
selectionHasStyle and selectionStartHasStyle should use EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=55902
selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.
* WebView/WebHTMLView.mm: Removed unused selectionHasStyle.
(-[WebHTMLView validateUserInterfaceItemWithoutDelegate:]): Calls Editor::selectionHasStyle.
2011-03-07 Dan Bernstein <mitz@apple.com>
LLVM Compiler build fix.
......
......@@ -2643,14 +2643,6 @@ WEBCORE_COMMAND(yankAndSelect)
coreFrame->selection()->revealSelection(ScrollAlignment::alignCenterAlways);
}
- (NSCellStateValue)selectionHasStyle:(CSSStyleDeclaration*)style
{
Frame* coreFrame = core([self _frame]);
if (!coreFrame)
return NSOffState;
return kit(coreFrame->editor()->selectionHasStyle(style));
}
- (BOOL)validateUserInterfaceItemWithoutDelegate:(id <NSValidatedUserInterfaceItem>)item
{
SEL action = [item action];
......@@ -2706,10 +2698,8 @@ WEBCORE_COMMAND(yankAndSelect)
NSMenuItem *menuItem = (NSMenuItem *)item;
if ([menuItem isKindOfClass:[NSMenuItem class]]) {
RefPtr<CSSStyleDeclaration> style = CSSMutableStyleDeclaration::create();
ExceptionCode ec;
style->setProperty("direction", writingDirection == NSWritingDirectionLeftToRight ? "LTR" : "RTL", ec);
[menuItem setState:frame->editor()->selectionHasStyle(style.get())];
String direction = writingDirection == NSWritingDirectionLeftToRight ? "ltr" : "rtl";
[menuItem setState:frame->editor()->selectionHasStyle(CSSPropertyDirection, direction)];
}
return [self _canEdit];
}
......@@ -2724,12 +2714,9 @@ WEBCORE_COMMAND(yankAndSelect)
if (action == @selector(toggleBaseWritingDirection:)) {
NSMenuItem *menuItem = (NSMenuItem *)item;
if ([menuItem isKindOfClass:[NSMenuItem class]]) {
RefPtr<CSSStyleDeclaration> style = CSSMutableStyleDeclaration::create();
ExceptionCode ec;
style->setProperty("direction", "RTL", ec);
// Take control of the title of the menu item instead of just checking/unchecking it because
// a check would be ambiguous.
[menuItem setTitle:frame->editor()->selectionHasStyle(style.get())
[menuItem setTitle:frame->editor()->selectionHasStyle(CSSPropertyDirection, "rtl")
? UI_STRING_INTERNAL("Left to Right", "Left to Right context menu item")
: UI_STRING_INTERNAL("Right to Left", "Right to Left context menu item")];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment