Skip to content

Commit

Permalink
Replace blink::TextStyle enum with ax::mojom::TextStyle
Browse files Browse the repository at this point in the history
Follow-up to other similar patches.

This also fixes ax::mojom::TextStyle so that it
just encodes the possible flags for the bit fields,
rather than trying to encode every permutation of bits.

Bug: 882660
TBR=halliwell@chromium.org

Change-Id: If16be583e6ee35728116b568334b1b89aad0b2ef
Reviewed-on: https://chromium-review.googlesource.com/c/1300414
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604074}
  • Loading branch information
minorninth authored and Commit Bot committed Oct 31, 2018
1 parent a3bc216 commit 35e8215
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 230 deletions.
16 changes: 4 additions & 12 deletions chrome/renderer/extensions/automation_internal_custom_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -863,36 +863,28 @@ void AutomationInternalCustomBindings::AddRoutes() {
RouteNodeIDFunction(
"GetBold", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleBold)) != 0;
bool value = node->data().HasTextStyle(ax::mojom::TextStyle::kBold);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction(
"GetItalic", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleItalic)) != 0;
bool value = node->data().HasTextStyle(ax::mojom::TextStyle::kItalic);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction("GetUnderline", [](v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline)) != 0;
bool value = node->data().HasTextStyle(ax::mojom::TextStyle::kUnderline);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction(
"GetLineThrough",
[](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(
ax::mojom::TextStyle::kTextStyleLineThrough)) != 0;
node->data().HasTextStyle(ax::mojom::TextStyle::kLineThrough);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,36 +808,28 @@ void AutomationInternalCustomBindings::AddRoutes() {
RouteNodeIDFunction(
"GetBold", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleBold)) != 0;
bool value = node->data().HasTextStyle(ax::mojom::TextStyle::kBold);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction(
"GetItalic", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleItalic)) != 0;
bool value = node->data().HasTextStyle(ax::mojom::TextStyle::kItalic);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction("GetUnderline", [](v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline)) != 0;
bool value = node->data().HasTextStyle(ax::mojom::TextStyle::kUnderline);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction(
"GetLineThrough",
[](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper, ui::AXNode* node) {
bool value =
(node->data().GetIntAttribute(ax::mojom::IntAttribute::kTextStyle) &
static_cast<int32_t>(
ax::mojom::TextStyle::kTextStyleLineThrough)) != 0;
node->data().HasTextStyle(ax::mojom::TextStyle::kLineThrough);
result.Set(v8::Boolean::New(isolate, value));
});
RouteNodeIDFunction(
Expand Down
21 changes: 6 additions & 15 deletions content/browser/accessibility/browser_accessibility_com_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1966,25 +1966,16 @@ std::vector<base::string16> BrowserAccessibilityComWin::ComputeTextAttributes()

int32_t text_style =
owner()->GetIntAttribute(ax::mojom::IntAttribute::kTextStyle);
if (text_style != static_cast<int32_t>(ax::mojom::TextStyle::kNone)) {
if (text_style &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleItalic)) {
attributes.push_back(L"font-style:italic");
}

if (text_style &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleBold)) {
if (text_style) {
if (GetData().HasTextStyle(ax::mojom::TextStyle::kBold))
attributes.push_back(L"font-weight:bold");
}

if (text_style &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleLineThrough)) {
if (GetData().HasTextStyle(ax::mojom::TextStyle::kItalic))
attributes.push_back(L"font-style:italic");
if (GetData().HasTextStyle(ax::mojom::TextStyle::kLineThrough)) {
// TODO(nektar): Figure out a more specific value.
attributes.push_back(L"text-line-through-style:solid");
}

if (text_style &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline)) {
if (GetData().HasTextStyle(ax::mojom::TextStyle::kUnderline)) {
// TODO(nektar): Figure out a more specific value.
attributes.push_back(L"text-underline-style:solid");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1652,10 +1652,8 @@ TEST_F(BrowserAccessibilityTest, TestTextAttributesInContentEditables) {
text_before.role = ax::mojom::Role::kStaticText;
text_before.AddState(ax::mojom::State::kEditable);
text_before.SetName("Before ");
text_before.AddIntAttribute(
ax::mojom::IntAttribute::kTextStyle,
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleBold) |
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleItalic));
text_before.AddTextStyle(ax::mojom::TextStyle::kBold);
text_before.AddTextStyle(ax::mojom::TextStyle::kItalic);

ui::AXNodeData link;
link.id = 4;
Expand All @@ -1664,9 +1662,7 @@ TEST_F(BrowserAccessibilityTest, TestTextAttributesInContentEditables) {
link.AddState(ax::mojom::State::kFocusable);
link.AddState(ax::mojom::State::kLinked);
link.SetName("lnk");
link.AddIntAttribute(
ax::mojom::IntAttribute::kTextStyle,
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline));
link.AddTextStyle(ax::mojom::TextStyle::kUnderline);

ui::AXNodeData link_text;
link_text.id = 5;
Expand All @@ -1675,9 +1671,7 @@ TEST_F(BrowserAccessibilityTest, TestTextAttributesInContentEditables) {
link_text.AddState(ax::mojom::State::kFocusable);
link_text.AddState(ax::mojom::State::kLinked);
link_text.SetName("lnk");
link_text.AddIntAttribute(
ax::mojom::IntAttribute::kTextStyle,
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline));
link_text.AddTextStyle(ax::mojom::TextStyle::kUnderline);

// The name "lnk" is misspelled.
std::vector<int32_t> marker_types{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,23 +434,17 @@ bool AccessibilityTextfieldPredicate(

bool AccessibilityTextStyleBoldPredicate(
BrowserAccessibility* start, BrowserAccessibility* node) {
int32_t style = node->GetIntAttribute(ax::mojom::IntAttribute::kTextStyle);
return 0 !=
(style & static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleBold));
return node->GetData().HasTextStyle(ax::mojom::TextStyle::kBold);
}

bool AccessibilityTextStyleItalicPredicate(
BrowserAccessibility* start, BrowserAccessibility* node) {
int32_t style = node->GetIntAttribute(ax::mojom::IntAttribute::kTextStyle);
return 0 !=
(style & static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleItalic));
return node->GetData().HasTextStyle(ax::mojom::TextStyle::kItalic);
}

bool AccessibilityTextStyleUnderlinePredicate(
BrowserAccessibility* start, BrowserAccessibility* node) {
int32_t style = node->GetIntAttribute(ax::mojom::IntAttribute::kTextStyle);
return 0 != (style &
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline));
return node->GetData().HasTextStyle(ax::mojom::TextStyle::kUnderline);
}

bool AccessibilityTreePredicate(
Expand Down
18 changes: 0 additions & 18 deletions content/renderer/accessibility/blink_ax_enum_conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@

namespace content {

ax::mojom::TextStyle AXTextStyleFromBlink(blink::WebAXTextStyle text_style) {
uint32_t browser_text_style =
static_cast<uint32_t>(ax::mojom::TextStyle::kNone);
if (text_style & blink::kWebAXTextStyleBold)
browser_text_style |=
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleBold);
if (text_style & blink::kWebAXTextStyleItalic)
browser_text_style |=
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleItalic);
if (text_style & blink::kWebAXTextStyleUnderline)
browser_text_style |=
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleUnderline);
if (text_style & blink::kWebAXTextStyleLineThrough)
browser_text_style |=
static_cast<int32_t>(ax::mojom::TextStyle::kTextStyleLineThrough);
return static_cast<ax::mojom::TextStyle>(browser_text_style);
}

void AXStateFromBlink(const blink::WebAXObject& o, ui::AXNodeData* dst) {
blink::WebAXExpanded expanded = o.IsExpanded();
if (expanded) {
Expand Down
2 changes: 0 additions & 2 deletions content/renderer/accessibility/blink_ax_enum_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace content {

ax::mojom::TextStyle AXTextStyleFromBlink(blink::WebAXTextStyle text_style);

// Provides a conversion between the WebAXObject state
// accessors and a state bitmask stored in an AXNodeData.
// (Note that some rare states are sent as boolean attributes
Expand Down
5 changes: 2 additions & 3 deletions content/renderer/accessibility/blink_ax_tree_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,8 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src,
}

if (src.TextStyle()) {
dst->AddIntAttribute(
ax::mojom::IntAttribute::kTextStyle,
static_cast<int32_t>(AXTextStyleFromBlink(src.TextStyle())));
dst->AddIntAttribute(ax::mojom::IntAttribute::kTextStyle,
src.TextStyle());
}

if (dst->role == ax::mojom::Role::kInlineTextBox) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE offset:0 ia2_hypertext='<obj0><obj1>'
++IA2_ROLE_PARAGRAPH offset:0 offset:4 font-weight:bold offset:9 offset:10 font-style:italic offset:15 offset:16 text-underline-style:solid offset:19 offset:20 font-style:italic font-weight:bold offset:26 offset:27 font-style:italic text-underline-style:solid offset:31 offset:32 font-style:italic font-weight:bold text-underline-style:solid ia2_hypertext='The quick brown fox jumped over dog'
++IA2_ROLE_PARAGRAPH offset:0 offset:4 font-weight:bold offset:9 offset:10 font-style:italic offset:15 offset:16 text-underline-style:solid offset:19 offset:20 font-weight:bold font-style:italic offset:26 offset:27 font-style:italic text-underline-style:solid offset:31 offset:32 font-weight:bold font-style:italic text-underline-style:solid ia2_hypertext='The quick brown fox jumped over dog'
++++ROLE_SYSTEM_STATICTEXT name='The ' offset:0 ia2_hypertext='The '
++++ROLE_SYSTEM_STATICTEXT name='quick' offset:0 font-weight:bold ia2_hypertext='quick'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='brown' offset:0 font-style:italic ia2_hypertext='brown'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='fox' offset:0 text-underline-style:solid ia2_hypertext='fox'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='jumped' offset:0 font-style:italic font-weight:bold ia2_hypertext='jumped'
++++ROLE_SYSTEM_STATICTEXT name='jumped' offset:0 font-weight:bold font-style:italic ia2_hypertext='jumped'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='over' offset:0 font-style:italic text-underline-style:solid ia2_hypertext='over'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='dog' offset:0 font-style:italic font-weight:bold text-underline-style:solid ia2_hypertext='dog'
++++ROLE_SYSTEM_STATICTEXT name='dog' offset:0 font-weight:bold font-style:italic text-underline-style:solid ia2_hypertext='dog'
++IA2_ROLE_SECTION value='Normal bold italic underline line-through subscript superscript' FOCUSABLE IA2_STATE_MULTI_LINE text-model:a1 offset:0 offset:7 font-weight:bold offset:11 offset:12 font-style:italic offset:18 offset:19 text-underline-style:solid offset:28 offset:29 text-line-through-style:solid offset:41 offset:42 text-position:sub offset:51 offset:52 text-position:super ia2_hypertext='Normal bold italic underline line-through subscript superscript'
++++ROLE_SYSTEM_STATICTEXT name='Normal' offset:0 ia2_hypertext='Normal'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
Expand All @@ -25,4 +25,4 @@ ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE offset:0 ia2_hypertext='<obj0><obj1>'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='subscript' offset:0 text-position:sub ia2_hypertext='subscript'
++++ROLE_SYSTEM_STATICTEXT name=' ' offset:0 ia2_hypertext=' '
++++ROLE_SYSTEM_STATICTEXT name='superscript' offset:0 text-position:super ia2_hypertext='superscript'
++++ROLE_SYSTEM_STATICTEXT name='superscript' offset:0 text-position:super ia2_hypertext='superscript'
9 changes: 0 additions & 9 deletions third_party/blink/public/web/web_ax_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@

namespace blink {

// Used for exposing text attributes.
enum WebAXTextStyle {
kWebAXTextStyleNone = 0,
kWebAXTextStyleBold = 1 << 0,
kWebAXTextStyleItalic = 1 << 1,
kWebAXTextStyleUnderline = 1 << 2,
kWebAXTextStyleLineThrough = 1 << 3
};

// Expanded State.
// These values must match blink::AccessibilityExpanded values.
// Enforced in AssertMatchingEnums.cpp.
Expand Down
3 changes: 2 additions & 1 deletion third_party/blink/public/web/web_ax_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class WebAXObject {
BLINK_EXPORT WebString StringValue() const;
BLINK_EXPORT ax::mojom::TextDirection GetTextDirection() const;
BLINK_EXPORT ax::mojom::TextPosition GetTextPosition() const;
BLINK_EXPORT WebAXTextStyle TextStyle() const;
// Bitmask from ax::mojom::TextStyle.
BLINK_EXPORT int32_t TextStyle() const;
BLINK_EXPORT WebURL Url() const;

// Retrieves the accessible name of the object, an enum indicating where the
Expand Down
6 changes: 0 additions & 6 deletions third_party/blink/renderer/modules/accessibility/ax_enums.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ STATIC_ASSERT_ENUM(kWebAXOrientationVertical,
STATIC_ASSERT_ENUM(kWebAXOrientationHorizontal,
kAccessibilityOrientationHorizontal);

STATIC_ASSERT_ENUM(kWebAXTextStyleNone, kTextStyleNone);
STATIC_ASSERT_ENUM(kWebAXTextStyleBold, kTextStyleBold);
STATIC_ASSERT_ENUM(kWebAXTextStyleItalic, kTextStyleItalic);
STATIC_ASSERT_ENUM(kWebAXTextStyleUnderline, kTextStyleUnderline);
STATIC_ASSERT_ENUM(kWebAXTextStyleLineThrough, kTextStyleLineThrough);

STATIC_ASSERT_ENUM(WebAXStringAttribute::kAriaKeyShortcuts,
AXStringAttribute::kAriaKeyShortcuts);
STATIC_ASSERT_ENUM(WebAXStringAttribute::kAriaRoleDescription,
Expand Down
8 changes: 0 additions & 8 deletions third_party/blink/renderer/modules/accessibility/ax_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ enum AccessibilitySelectedState {
kSelectedStateTrue,
};

enum TextStyle {
kTextStyleNone = 0,
kTextStyleBold = 1 << 0,
kTextStyleItalic = 1 << 1,
kTextStyleUnderline = 1 << 2,
kTextStyleLineThrough = 1 << 3
};

enum class AXBoolAttribute {
kAriaBusy,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,25 +1216,29 @@ int AXLayoutObject::TextLength() const {
return GetText().length();
}

TextStyle AXLayoutObject::GetTextStyle() const {
static unsigned TextStyleFlag(ax::mojom::TextStyle text_style_enum) {
return static_cast<unsigned>(1 << static_cast<int>(text_style_enum));
}

int32_t AXLayoutObject::GetTextStyle() const {
if (!GetLayoutObject())
return AXNodeObject::GetTextStyle();

const ComputedStyle* style = GetLayoutObject()->Style();
if (!style)
return AXNodeObject::GetTextStyle();

unsigned text_style = kTextStyleNone;
int32_t text_style = 0;
if (style->GetFontWeight() == BoldWeightValue())
text_style |= kTextStyleBold;
text_style |= TextStyleFlag(ax::mojom::TextStyle::kBold);
if (style->GetFontDescription().Style() == ItalicSlopeValue())
text_style |= kTextStyleItalic;
text_style |= TextStyleFlag(ax::mojom::TextStyle::kItalic);
if (style->GetTextDecoration() == TextDecoration::kUnderline)
text_style |= kTextStyleUnderline;
text_style |= TextStyleFlag(ax::mojom::TextStyle::kUnderline);
if (style->GetTextDecoration() == TextDecoration::kLineThrough)
text_style |= kTextStyleLineThrough;
text_style |= TextStyleFlag(ax::mojom::TextStyle::kLineThrough);

return static_cast<TextStyle>(text_style);
return text_style;
}

KURL AXLayoutObject::Url() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MODULES_EXPORT AXLayoutObject : public AXNodeObject {
ax::mojom::TextDirection GetTextDirection() const final;
ax::mojom::TextPosition GetTextPosition() const final;
int TextLength() const override;
TextStyle GetTextStyle() const final;
int32_t GetTextStyle() const final;
KURL Url() const override;

// Inline text boxes.
Expand Down
5 changes: 4 additions & 1 deletion third_party/blink/renderer/modules/accessibility/ax_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,10 @@ class MODULES_EXPORT AXObject : public GarbageCollectedFinalized<AXObject> {
return ax::mojom::TextPosition::kNone;
}
virtual int TextLength() const { return 0; }
virtual TextStyle GetTextStyle() const { return kTextStyleNone; }

// Bitmask from ax::mojom::TextStyle.
virtual int32_t GetTextStyle() const { return 0; }

virtual AXObjectVector RadioButtonsInGroup() const {
return AXObjectVector();
}
Expand Down
6 changes: 3 additions & 3 deletions third_party/blink/renderer/modules/exported/web_ax_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,11 @@ ax::mojom::TextPosition WebAXObject::GetTextPosition() const {
return private_->GetTextPosition();
}

WebAXTextStyle WebAXObject::TextStyle() const {
int WebAXObject::TextStyle() const {
if (IsDetached())
return kWebAXTextStyleNone;
return 0;

return static_cast<WebAXTextStyle>(private_->GetTextStyle());
return private_->GetTextStyle();
}

WebURL WebAXObject::Url() const {
Expand Down
Loading

0 comments on commit 35e8215

Please sign in to comment.