From e728f6004b45c72fab28acd2277f86d813acf140 Mon Sep 17 00:00:00 2001 From: "masayuki%d-toybox.com" Date: Wed, 16 May 2007 15:51:39 +0000 Subject: [PATCH] Bug 279246 Implement 'ime-mode' property (WinIE CSS) r+sr=dbaron --- dom/public/idl/css/nsIDOMCSS2Properties.idl | 5 ++- editor/libeditor/base/nsEditor.cpp | 43 +++++++++++++++++---- layout/base/nsStyleConsts.h | 7 ++++ layout/style/forms.css | 1 + layout/style/nsCSSKeywordList.h | 2 + layout/style/nsCSSParser.cpp | 3 ++ layout/style/nsCSSPropList.h | 1 + layout/style/nsCSSProps.cpp | 7 ++++ layout/style/nsCSSProps.h | 1 + layout/style/nsCSSStruct.cpp | 3 +- layout/style/nsCSSStruct.h | 1 + layout/style/nsComputedDOMStyle.cpp | 22 +++++++++++ layout/style/nsComputedDOMStyle.h | 1 + layout/style/nsRuleNode.cpp | 16 ++++++++ layout/style/nsStyleContext.cpp | 5 ++- layout/style/nsStyleStruct.cpp | 3 ++ layout/style/nsStyleStruct.h | 1 + layout/style/test/property_database.js | 8 ++++ 18 files changed, 119 insertions(+), 11 deletions(-) diff --git a/dom/public/idl/css/nsIDOMCSS2Properties.idl b/dom/public/idl/css/nsIDOMCSS2Properties.idl index 5141c33a51e..8e799d7cd7d 100644 --- a/dom/public/idl/css/nsIDOMCSS2Properties.idl +++ b/dom/public/idl/css/nsIDOMCSS2Properties.idl @@ -406,7 +406,7 @@ interface nsIDOMCSS2Properties : nsISupports // raises(DOMException) on setting }; -[scriptable, uuid(06b42e9d-61b5-400d-9561-b43f0e9883c0)] +[scriptable, uuid(8c2e3658-1fe4-452a-92be-b0afaf76f897)] interface nsIDOMNSCSS2Properties : nsIDOMCSS2Properties { /* Non-DOM 2 extensions */ @@ -564,4 +564,7 @@ interface nsIDOMNSCSS2Properties : nsIDOMCSS2Properties attribute DOMString overflowY; // raises(DOMException) on setting + attribute DOMString imeMode; + // raises(DOMException) on setting + }; diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 015b63434a4..91e46b2f9a1 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -2206,16 +2206,45 @@ NS_IMETHODIMP nsEditor::GetPreferredIMEState(PRUint32 *aState) { NS_ENSURE_ARG_POINTER(aState); + *aState = nsIContent::IME_STATUS_ENABLE; PRUint32 flags; - if (NS_SUCCEEDED(GetFlags(&flags)) && - flags & (nsIPlaintextEditor::eEditorReadonlyMask | - nsIPlaintextEditor::eEditorDisabledMask)) + nsresult rv = GetFlags(&flags); + NS_ENSURE_SUCCESS(rv, rv); + + if (flags & (nsIPlaintextEditor::eEditorReadonlyMask | + nsIPlaintextEditor::eEditorDisabledMask)) { *aState = nsIContent::IME_STATUS_DISABLE; - else if (flags & nsIPlaintextEditor::eEditorPasswordMask) - *aState = nsIContent::IME_STATUS_PASSWORD; - else - *aState = nsIContent::IME_STATUS_ENABLE; + return NS_OK; + } + + nsCOMPtr presShell; + rv = GetPresShell(getter_AddRefs(presShell)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr content = do_QueryInterface(GetRoot()); + NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); + + nsIFrame* frame = presShell->GetPrimaryFrameFor(content); + NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); + + switch (frame->GetStyleUIReset()->mIMEMode) { + case NS_STYLE_IME_MODE_AUTO: + if (flags & (nsIPlaintextEditor::eEditorPasswordMask)) + *aState = nsIContent::IME_STATUS_PASSWORD; + break; + case NS_STYLE_IME_MODE_DISABLED: + // we should use password state for |ime-mode: disabled;|. + *aState = nsIContent::IME_STATUS_PASSWORD; + break; + case NS_STYLE_IME_MODE_ACTIVE: + *aState |= nsIContent::IME_STATUS_OPEN; + break; + case NS_STYLE_IME_MODE_INACTIVE: + *aState |= nsIContent::IME_STATUS_CLOSE; + break; + } + return NS_OK; } diff --git a/layout/base/nsStyleConsts.h b/layout/base/nsStyleConsts.h index f513db59551..fc01dfcff96 100644 --- a/layout/base/nsStyleConsts.h +++ b/layout/base/nsStyleConsts.h @@ -653,6 +653,13 @@ #define NS_STYLE_COLUMN_COUNT_AUTO 0 #define NS_STYLE_COLUMN_COUNT_UNLIMITED (-1) +// See nsStyleUIReset +#define NS_STYLE_IME_MODE_AUTO 0 +#define NS_STYLE_IME_MODE_NORMAL 1 +#define NS_STYLE_IME_MODE_ACTIVE 2 +#define NS_STYLE_IME_MODE_DISABLED 3 +#define NS_STYLE_IME_MODE_INACTIVE 4 + #ifdef MOZ_SVG // See nsStyleSVG diff --git a/layout/style/forms.css b/layout/style/forms.css index b783d6b8dac..0f93b435c55 100644 --- a/layout/style/forms.css +++ b/layout/style/forms.css @@ -131,6 +131,7 @@ input > .anonymous-div { /* XXXldb I'm not sure if we really want the 'text-decoration: inherit', but it's needed to make 'text-decoration' "work" on text inputs. */ text-decoration: inherit; + ime-mode: inherit; } select { diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h index fc675877e11..06fc20650a7 100644 --- a/layout/style/nsCSSKeywordList.h +++ b/layout/style/nsCSSKeywordList.h @@ -181,6 +181,7 @@ CSS_KEY(-moz-zoom-in, _moz_zoom_in) CSS_KEY(-moz-zoom-out, _moz_zoom_out) CSS_KEY(above, above) CSS_KEY(absolute, absolute) +CSS_KEY(active, active) CSS_KEY(activeborder, activeborder) CSS_KEY(activecaption, activecaption) CSS_KEY(alias, alias) @@ -284,6 +285,7 @@ CSS_KEY(hz, hz) CSS_KEY(icon, icon) CSS_KEY(ignore, ignore) CSS_KEY(in, in) +CSS_KEY(inactive, inactive) CSS_KEY(inactiveborder, inactiveborder) CSS_KEY(inactivecaption, inactivecaption) CSS_KEY(inactivecaptiontext, inactivecaptiontext) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index b1f39df47a4..e60dc2d13bf 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -4694,6 +4694,9 @@ PRBool CSSParserImpl::ParseSingleValueProperty(nsresult& aErrorCode, nsCSSProps::kFontVariantKTable); case eCSSProperty_font_weight: return ParseFontWeight(aErrorCode, aValue); + case eCSSProperty_ime_mode: + return ParseVariant(aErrorCode, aValue, VARIANT_AHK | VARIANT_NORMAL, + nsCSSProps::kIMEModeKTable); case eCSSProperty_letter_spacing: case eCSSProperty_word_spacing: return ParseVariant(aErrorCode, aValue, VARIANT_HL | VARIANT_NORMAL, nsnull); diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index f0e6c6d7b3d..aa1f28613f9 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -339,6 +339,7 @@ CSS_PROP_FONT(font-weight, font_weight, FontWeight, Font, mWeight, eCSSType_Valu CSS_PROP_UIRESET(-moz-force-broken-image-icon, force_broken_image_icon, MozForceBrokenImageIcon, UserInterface, mForceBrokenImageIcon, eCSSType_Value, nsnull) // bug 58646 CSS_PROP_POSITION(height, height, Height, Position, mHeight, eCSSType_Value, nsnull) CSS_PROP_LIST(-moz-image-region, image_region, MozImageRegion, List, mImageRegion, eCSSType_Rect, nsnull) +CSS_PROP_UIRESET(ime-mode, ime_mode, ImeMode, UserInterface, mIMEMode, eCSSType_Value, kIMEModeKTable) CSS_PROP_POSITION(left, left, Left, Position, mOffset.mLeft, eCSSType_Value, nsnull) CSS_PROP_TEXT(letter-spacing, letter_spacing, LetterSpacing, Text, mLetterSpacing, eCSSType_Value, nsnull) CSS_PROP_TEXT(line-height, line_height, LineHeight, Text, mLineHeight, eCSSType_Value, nsnull) diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index 36a6fcfdc1b..5276272ab30 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -646,6 +646,13 @@ const PRInt32 nsCSSProps::kFontWeightKTable[] = { eCSSKeyword_UNKNOWN,-1 }; +const PRInt32 nsCSSProps::kIMEModeKTable[] = { + eCSSKeyword_active, NS_STYLE_IME_MODE_ACTIVE, + eCSSKeyword_disabled, NS_STYLE_IME_MODE_DISABLED, + eCSSKeyword_inactive, NS_STYLE_IME_MODE_INACTIVE, + eCSSKeyword_UNKNOWN,-1 +}; + // XXX What's the point? const PRInt32 nsCSSProps::kKeyEquivalentKTable[] = { eCSSKeyword_UNKNOWN,-1 diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h index 96feed91daa..b306593c7bd 100644 --- a/layout/style/nsCSSProps.h +++ b/layout/style/nsCSSProps.h @@ -159,6 +159,7 @@ public: static const PRInt32 kFontVariantKTable[]; static const PRInt32 kFontWeightKTable[]; static const PRInt32 kKeyEquivalentKTable[]; + static const PRInt32 kIMEModeKTable[]; static const PRInt32 kListStylePositionKTable[]; static const PRInt32 kListStyleKTable[]; static const PRInt32 kOutlineStyleKTable[]; diff --git a/layout/style/nsCSSStruct.cpp b/layout/style/nsCSSStruct.cpp index 5a158d0e371..f70474d16e0 100644 --- a/layout/style/nsCSSStruct.cpp +++ b/layout/style/nsCSSStruct.cpp @@ -565,7 +565,8 @@ nsCSSUserInterface::nsCSSUserInterface(const nsCSSUserInterface& aCopy) mUserSelect(aCopy.mUserSelect), mUserFocus(aCopy.mUserFocus), mCursor(nsnull), - mForceBrokenImageIcon(aCopy.mForceBrokenImageIcon) + mForceBrokenImageIcon(aCopy.mForceBrokenImageIcon), + mIMEMode(aCopy.mIMEMode) { MOZ_COUNT_CTOR(nsCSSUserInterface); CSS_IF_COPY(mCursor, nsCSSValueList); diff --git a/layout/style/nsCSSStruct.h b/layout/style/nsCSSStruct.h index ab0940abab2..6223aea221e 100644 --- a/layout/style/nsCSSStruct.h +++ b/layout/style/nsCSSStruct.h @@ -427,6 +427,7 @@ struct nsCSSUserInterface : public nsCSSStruct { // NEW nsCSSValueList* mCursor; nsCSSValue mForceBrokenImageIcon; + nsCSSValue mIMEMode; }; struct nsRuleDataUserInterface : public nsCSSUserInterface { diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index cd2615c86e3..cf69eae1627 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -1896,6 +1896,27 @@ nsComputedDOMStyle::GetFloatEdge(nsIDOMCSSValue** aValue) return CallQueryInterface(val, aValue); } +nsresult +nsComputedDOMStyle::GetIMEMode(nsIDOMCSSValue** aValue) +{ + nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue(); + NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); + + const nsStyleUIReset *uiData = GetStyleUIReset(); + + nsCSSKeyword keyword; + if (uiData->mIMEMode == NS_STYLE_IME_MODE_AUTO) { + keyword = eCSSKeyword_auto; + } else if (uiData->mIMEMode == NS_STYLE_IME_MODE_NORMAL) { + keyword = eCSSKeyword_normal; + } else { + keyword = nsCSSProps::ValueToKeywordEnum(uiData->mIMEMode, + nsCSSProps::kIMEModeKTable); + } + val->SetIdent(nsCSSKeywords::GetStringValue(keyword)); + + return CallQueryInterface(val, aValue); +} nsresult nsComputedDOMStyle::GetUserFocus(nsIDOMCSSValue** aValue) @@ -2960,6 +2981,7 @@ nsComputedDOMStyle::GetQueryablePropertyMap(PRUint32* aLength) COMPUTED_STYLE_MAP_ENTRY(max_width, MaxWidth), COMPUTED_STYLE_MAP_ENTRY(min_height, MinHeight), COMPUTED_STYLE_MAP_ENTRY(min_width, MinWidth), + COMPUTED_STYLE_MAP_ENTRY(ime_mode, IMEMode), COMPUTED_STYLE_MAP_ENTRY(opacity, Opacity), // COMPUTED_STYLE_MAP_ENTRY(orphans, Orphans), //// COMPUTED_STYLE_MAP_ENTRY(outline, Outline), diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index 55246de4bf3..275cc34bb2a 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -255,6 +255,7 @@ private: /* User interface properties */ nsresult GetCursor(nsIDOMCSSValue** aValue); + nsresult GetIMEMode(nsIDOMCSSValue** aValue); nsresult GetUserFocus(nsIDOMCSSValue** aValue); nsresult GetUserInput(nsIDOMCSSValue** aValue); nsresult GetUserModify(nsIDOMCSSValue** aValue); diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index b72f2d459b2..2dd0e786e48 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -2616,6 +2616,22 @@ nsRuleNode::ComputeUIResetData(nsStyleStruct* aStartStruct, ui->mUserSelect = parentUI->mUserSelect; } + // ime-mode: auto, normal, enum, inherit + if (eCSSUnit_Auto == uiData.mIMEMode.GetUnit() || + eCSSUnit_Initial == uiData.mIMEMode.GetUnit()) { + ui->mIMEMode = NS_STYLE_IME_MODE_AUTO; + } + else if (eCSSUnit_Normal == uiData.mIMEMode.GetUnit()) { + ui->mIMEMode = NS_STYLE_IME_MODE_NORMAL; + } + else if (eCSSUnit_Enumerated == uiData.mIMEMode.GetUnit()) { + ui->mIMEMode = uiData.mIMEMode.GetIntValue(); + } + else if (eCSSUnit_Inherit == uiData.mIMEMode.GetUnit()) { + inherited = PR_TRUE; + ui->mIMEMode = parentUI->mIMEMode; + } + // force-broken-image-icons: integer if (eCSSUnit_Integer == uiData.mForceBrokenImageIcon.GetUnit()) { ui->mForceBrokenImageIcon = uiData.mForceBrokenImageIcon.GetIntValue(); diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index 3510061caa6..e60ce7d0705 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -820,8 +820,9 @@ void nsStyleContext::DumpRegressionData(nsPresContext* aPresContext, FILE* out, // UIReset IndentBy(out,aIndent); const nsStyleUIReset* uiReset = GetStyleUIReset(); - fprintf(out, "\n", - (int)uiReset->mUserSelect); + fprintf(out, "\n", + (int)uiReset->mUserSelect, + (int)uiReset->mIMEMode); // Column IndentBy(out,aIndent); diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 16918d029ea..d881098839f 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1643,12 +1643,14 @@ nsStyleUIReset::nsStyleUIReset(void) { mUserSelect = NS_STYLE_USER_SELECT_AUTO; mForceBrokenImageIcon = 0; + mIMEMode = NS_STYLE_IME_MODE_AUTO; } nsStyleUIReset::nsStyleUIReset(const nsStyleUIReset& aSource) { mUserSelect = aSource.mUserSelect; mForceBrokenImageIcon = aSource.mForceBrokenImageIcon; + mIMEMode = aSource.mIMEMode; } nsStyleUIReset::~nsStyleUIReset(void) @@ -1657,6 +1659,7 @@ nsStyleUIReset::~nsStyleUIReset(void) nsChangeHint nsStyleUIReset::CalcDifference(const nsStyleUIReset& aOther) const { + // ignore mIMEMode if (mForceBrokenImageIcon == aOther.mForceBrokenImageIcon) { if (mUserSelect == aOther.mUserSelect) { return NS_STYLE_HINT_NONE; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index bb0edc9c688..d004a90aa0c 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -1125,6 +1125,7 @@ struct nsStyleUIReset: public nsStyleStruct { PRUint8 mUserSelect; // [reset] (selection-style) PRUint8 mForceBrokenImageIcon; // [reset] (0 if not forcing, otherwise forcing) + PRUint8 mIMEMode; // [reset] }; struct nsCursorImage { diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index 4ad42fc630b..efb439c1f7f 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -871,6 +871,14 @@ var gCSSProperties = { other_values: [ "15px", "3em", "15%" ], invalid_values: [ "none", "-moz-intrinsic", "-moz-min-intrinsic", "-moz-shrink-wrap", "-moz-fill" ] }, + "ime-mode": { + domProp: "imeMode", + inherited: false, + type: CSS_TYPE_LONGHAND, + initial_values: [ "auto" ], + other_values: [ "normal", "disabled", "active", "inactive" ], + invalid_values: [ "none", "enabled", "1px" ] + }, "left": { domProp: "left", inherited: false,