Commit f760cfbb authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Rework SVGStringList to match SVGProperty object lists

This moves DOM interface operations to the tear-off class, similarly to
how SVGProperty object lists are structured.

Change SVGStringListTearOff to inherit from SVGPropertyTearOffBase
rather than SVGPropertyTearOff<T> since since this type is never
animated, and thus does not need the ability to re-target to another
object.

Bug: 1106762
Change-Id: Ic8040339e3a3cdf6a818333dd77bdf15af3829ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302755Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#800946}
parent 2519d6aa
...@@ -94,7 +94,7 @@ void Dactyloscoper::RecordDirectSurface( ...@@ -94,7 +94,7 @@ void Dactyloscoper::RecordDirectSurface(
void Dactyloscoper::RecordDirectSurface(ExecutionContext* context, void Dactyloscoper::RecordDirectSurface(ExecutionContext* context,
WebFeature feature, WebFeature feature,
SVGStringListTearOff* strings) { SVGStringListTearOff* strings) {
RecordDirectSurface(context, feature, strings->Target()->Values()); RecordDirectSurface(context, feature, strings->Values());
} }
} // namespace blink } // namespace blink
...@@ -75,10 +75,8 @@ void SVGStaticStringList::AnimationEnded() { ...@@ -75,10 +75,8 @@ void SVGStaticStringList::AnimationEnded() {
} }
SVGStringListTearOff* SVGStaticStringList::TearOff() { SVGStringListTearOff* SVGStaticStringList::TearOff() {
if (!tear_off_) { if (!tear_off_)
tear_off_ = MakeGarbageCollected<SVGStringListTearOff>( tear_off_ = MakeGarbageCollected<SVGStringListTearOff>(value_, this);
value_, this, kPropertyIsNotAnimVal);
}
return tear_off_.Get(); return tear_off_.Get();
} }
......
...@@ -21,62 +21,29 @@ ...@@ -21,62 +21,29 @@
#include "third_party/blink/renderer/core/svg/svg_string_list.h" #include "third_party/blink/renderer/core/svg/svg_string_list.h"
#include "third_party/blink/renderer/core/svg/svg_parser_utilities.h" #include "third_party/blink/renderer/core/svg/svg_parser_utilities.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
namespace blink { namespace blink {
SVGStringListBase::~SVGStringListBase() = default; SVGStringListBase::~SVGStringListBase() = default;
void SVGStringListBase::Initialize(const String& item) { void SVGStringListBase::Clear() {
values_.clear(); values_.clear();
values_.push_back(item);
} }
String SVGStringListBase::GetItem(uint32_t index, void SVGStringListBase::Insert(uint32_t index, const String& new_item) {
ExceptionState& exception_state) {
if (!CheckIndexBound(index, exception_state))
return String();
return values_.at(index);
}
void SVGStringListBase::InsertItemBefore(const String& new_item,
uint32_t index) {
// Spec: If the index is greater than or equal to numberOfItems, then the new
// item is appended to the end of the list.
if (index > values_.size())
index = values_.size();
// Spec: Inserts a new item into the list at the specified position. The index
// of the item before which the new item is to be inserted. The first item is
// number 0. If the index is equal to 0, then the new item is inserted at the
// front of the list.
values_.insert(index, new_item); values_.insert(index, new_item);
} }
String SVGStringListBase::RemoveItem(uint32_t index, void SVGStringListBase::Remove(uint32_t index) {
ExceptionState& exception_state) {
if (!CheckIndexBound(index, exception_state))
return String();
String old_item = values_.at(index);
values_.EraseAt(index); values_.EraseAt(index);
return old_item;
} }
void SVGStringListBase::AppendItem(const String& new_item) { void SVGStringListBase::Append(const String& new_item) {
values_.push_back(new_item); values_.push_back(new_item);
} }
void SVGStringListBase::ReplaceItem(const String& new_item, void SVGStringListBase::Replace(uint32_t index, const String& new_item) {
uint32_t index,
ExceptionState& exception_state) {
if (!CheckIndexBound(index, exception_state))
return;
// Update the value at the desired position 'index'.
values_[index] = new_item; values_[index] = new_item;
} }
...@@ -138,19 +105,6 @@ String SVGStringListBase::ValueAsStringWithDelimiter( ...@@ -138,19 +105,6 @@ String SVGStringListBase::ValueAsStringWithDelimiter(
return builder.ToString(); return builder.ToString();
} }
bool SVGStringListBase::CheckIndexBound(uint32_t index,
ExceptionState& exception_state) {
if (index >= values_.size()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kIndexSizeError,
ExceptionMessages::IndexExceedsMaximumBound("index", index,
values_.size()));
return false;
}
return true;
}
void SVGStringListBase::Add(SVGPropertyBase* other, void SVGStringListBase::Add(SVGPropertyBase* other,
SVGElement* context_element) { SVGElement* context_element) {
// SVGStringList is never animated. // SVGStringList is never animated.
......
...@@ -33,11 +33,9 @@ ...@@ -33,11 +33,9 @@
#include "third_party/blink/renderer/core/svg/properties/svg_property_helper.h" #include "third_party/blink/renderer/core/svg/properties/svg_property_helper.h"
#include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h"
#include "third_party/blink/renderer/core/svg/svg_string.h"
namespace blink { namespace blink {
class ExceptionState;
class SVGStringListTearOff; class SVGStringListTearOff;
// Implementation of SVGStringList spec: // Implementation of SVGStringList spec:
...@@ -62,20 +60,16 @@ class SVGStringListBase : public SVGPropertyBase { ...@@ -62,20 +60,16 @@ class SVGStringListBase : public SVGPropertyBase {
const Vector<String>& Values() const { return values_; } const Vector<String>& Values() const { return values_; }
// SVGStringList DOM Spec implementation. These are only to be called from
// SVGStringListTearOff:
uint32_t length() { return values_.size(); } uint32_t length() { return values_.size(); }
void clear() { values_.clear(); } void Clear();
void Initialize(const String&); void Insert(uint32_t, const String&);
String GetItem(uint32_t, ExceptionState&); void Remove(uint32_t);
void InsertItemBefore(const String&, uint32_t); void Append(const String&);
String RemoveItem(uint32_t, ExceptionState&); void Replace(uint32_t, const String&);
void AppendItem(const String&);
void ReplaceItem(const String&, uint32_t, ExceptionState&);
// SVGPropertyBase:
virtual SVGParsingError SetValueAsString(const String&) = 0; virtual SVGParsingError SetValueAsString(const String&) = 0;
// SVGPropertyBase:
void Add(SVGPropertyBase*, SVGElement*) override; void Add(SVGPropertyBase*, SVGElement*) override;
void CalculateAnimatedValue(const SVGAnimateElement&, void CalculateAnimatedValue(const SVGAnimateElement&,
float percentage, float percentage,
...@@ -104,7 +98,6 @@ class SVGStringListBase : public SVGPropertyBase { ...@@ -104,7 +98,6 @@ class SVGStringListBase : public SVGPropertyBase {
void ParseInternal(const CharType*& ptr, void ParseInternal(const CharType*& ptr,
const CharType* end, const CharType* end,
char list_delimiter); char list_delimiter);
bool CheckIndexBound(uint32_t, ExceptionState&);
Vector<String> values_; Vector<String> values_;
}; };
......
...@@ -32,12 +32,8 @@ ...@@ -32,12 +32,8 @@
namespace blink { namespace blink {
SVGStringListTearOff::SVGStringListTearOff( SVGStringListTearOff::SVGStringListTearOff(SVGStringListBase* target,
SVGStringListBase* target, SVGAnimatedPropertyBase* binding)
SVGAnimatedPropertyBase* binding, : SVGPropertyTearOffBase(binding, kPropertyIsNotAnimVal), list_(target) {}
PropertyIsAnimValType property_is_anim_val)
: SVGPropertyTearOff<SVGStringListBase>(target,
binding,
property_is_anim_val) {}
} // namespace blink } // namespace blink
...@@ -37,50 +37,51 @@ ...@@ -37,50 +37,51 @@
namespace blink { namespace blink {
class SVGStringListTearOff : public SVGPropertyTearOff<SVGStringListBase> { class SVGStringListTearOff final : public SVGPropertyTearOffBase {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
SVGStringListTearOff(SVGStringListBase*, SVGStringListTearOff(SVGStringListBase*, SVGAnimatedPropertyBase* binding);
SVGAnimatedPropertyBase* binding,
PropertyIsAnimValType);
// SVGStringList DOM interface: // SVGStringList DOM interface:
// WebIDL requires "unsigned long" type which is uint32_t. // WebIDL requires "unsigned long" type which is uint32_t.
uint32_t length() { return Target()->length(); } uint32_t length() const { return list_->length(); }
void clear(ExceptionState& exception_state) { void clear(ExceptionState& exception_state) {
if (IsImmutable()) { DCHECK(!IsImmutable());
ThrowReadOnly(exception_state); list_->Clear();
return;
}
Target()->clear();
CommitChange(); CommitChange();
} }
String initialize(const String& item, ExceptionState& exception_state) { String initialize(const String& item, ExceptionState& exception_state) {
if (IsImmutable()) { DCHECK(!IsImmutable());
ThrowReadOnly(exception_state); list_->Clear();
return String(); list_->Append(item);
}
Target()->Initialize(item);
CommitChange(); CommitChange();
return item; return item;
} }
String getItem(uint32_t index, ExceptionState& exception_state) { String getItem(uint32_t index, ExceptionState& exception_state) const {
return Target()->GetItem(index, exception_state); if (index >= list_->length()) {
ThrowIndexSize(exception_state, index, list_->length());
return String();
}
return list_->Values()[index];
} }
String insertItemBefore(const String& item, String insertItemBefore(const String& item,
uint32_t index, uint32_t index,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (IsImmutable()) { DCHECK(!IsImmutable());
ThrowReadOnly(exception_state); // Spec: If the index is greater than or equal to numberOfItems, then the
return String(); // new item is appended to the end of the list.
} index = std::min(index, list_->length());
Target()->InsertItemBefore(item, index); // Spec: Inserts a new item into the list at the specified position. The
// index of the item before which the new item is to be inserted. The first
// item is number 0. If the index is equal to 0, then the new item is
// inserted at the front of the list.
list_->Insert(index, item);
CommitChange(); CommitChange();
return item; return item;
} }
...@@ -88,11 +89,12 @@ class SVGStringListTearOff : public SVGPropertyTearOff<SVGStringListBase> { ...@@ -88,11 +89,12 @@ class SVGStringListTearOff : public SVGPropertyTearOff<SVGStringListBase> {
String replaceItem(const String& item, String replaceItem(const String& item,
uint32_t index, uint32_t index,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (IsImmutable()) { DCHECK(!IsImmutable());
ThrowReadOnly(exception_state); if (index >= list_->length()) {
ThrowIndexSize(exception_state, index, list_->length());
return String(); return String();
} }
Target()->ReplaceItem(item, index, exception_state); list_->Replace(index, item);
CommitChange(); CommitChange();
return item; return item;
} }
...@@ -106,24 +108,33 @@ class SVGStringListTearOff : public SVGPropertyTearOff<SVGStringListBase> { ...@@ -106,24 +108,33 @@ class SVGStringListTearOff : public SVGPropertyTearOff<SVGStringListBase> {
} }
String removeItem(uint32_t index, ExceptionState& exception_state) { String removeItem(uint32_t index, ExceptionState& exception_state) {
if (IsImmutable()) { DCHECK(!IsImmutable());
ThrowReadOnly(exception_state); if (index >= list_->length()) {
ThrowIndexSize(exception_state, index, list_->length());
return String(); return String();
} }
String removed_item = Target()->RemoveItem(index, exception_state); String removed_item = list_->Values()[index];
list_->Remove(index);
CommitChange(); CommitChange();
return removed_item; return removed_item;
} }
String appendItem(const String& item, ExceptionState& exception_state) { String appendItem(const String& item, ExceptionState& exception_state) {
if (IsImmutable()) { DCHECK(!IsImmutable());
ThrowReadOnly(exception_state); list_->Append(item);
return String();
}
Target()->AppendItem(item);
CommitChange(); CommitChange();
return item; return item;
} }
void Trace(Visitor* visitor) const override {
visitor->Trace(list_);
SVGPropertyTearOffBase::Trace(visitor);
}
const Vector<String>& Values() const { return list_->Values(); }
private:
const Member<SVGStringListBase> list_;
}; };
} // namespace blink } // namespace blink
......
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