Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Unified Diff: Source/core/css/FontFaceSet.cpp

Issue 557763003: Add iterator support to FontFaceSet (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/FontFaceSet.h ('k') | Source/core/css/FontFaceSet.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/FontFaceSet.cpp
diff --git a/Source/core/css/FontFaceSet.cpp b/Source/core/css/FontFaceSet.cpp
index 7de6b7767b337a4fbd63a42f9d335aa1c360d6c2..b745eb83209f4f81ac940099b6189fbb3c94ccf3 100644
--- a/Source/core/css/FontFaceSet.cpp
+++ b/Source/core/css/FontFaceSet.cpp
@@ -29,6 +29,7 @@
#include "bindings/core/v8/Dictionary.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/V8FontFace.h"
#include "core/css/CSSFontSelector.h"
#include "core/css/CSSSegmentedFontFace.h"
#include "core/css/FontFaceCache.h"
@@ -387,6 +388,21 @@ void FontFaceSet::forEachInternal(PassOwnPtrWillBeRawPtr<FontFaceSetForEachCallb
}
}
+Iterator* FontFaceSet::keys()
+{
+ return new FontFaceSetIterator(this, FontFaceSetIterator::Keys);
+}
+
+Iterator* FontFaceSet::values()
+{
+ return new FontFaceSetIterator(this, FontFaceSetIterator::Values);
+}
+
+Iterator* FontFaceSet::entries()
+{
+ return new FontFaceSetIterator(this, FontFaceSetIterator::Entries);
+}
+
unsigned long FontFaceSet::size() const
{
if (!inActiveDocumentContext())
@@ -394,6 +410,27 @@ unsigned long FontFaceSet::size() const
return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size();
}
+FontFace* FontFaceSet::fontFaceAt(size_t index) const
+{
+ if (inActiveDocumentContext()) {
+ const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& cssConnectedFaces = cssConnectedFontFaceList();
+ if (index < cssConnectedFaces.size()) {
+ WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::const_iterator it = cssConnectedFaces.begin();
+ for (size_t i = 0; i < index; i++)
+ ++it;
+ return it->get();
+ }
+ index -= cssConnectedFaces.size();
+ }
+ if (index < m_nonCSSConnectedFaces.size()) {
+ WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::const_iterator it = m_nonCSSConnectedFaces.begin();
+ for (size_t i = 0; i < index; i++)
+ ++it;
+ return it->get();
+ }
+ return 0;
+}
+
void FontFaceSet::fireDoneEventIfPossible()
{
if (m_shouldFireLoadingEvent)
@@ -592,4 +629,20 @@ void FontFaceSet::trace(Visitor* visitor)
}
#endif
+ScriptValue FontFaceSet::FontFaceSetIterator::next(ScriptState* scriptState, ExceptionState&)
+{
+ FontFace* fontFace = m_fontFaceSet->fontFaceAt(m_index);
haraken 2014/09/11 12:06:07 Each next() method is O(n), and thus it takes O(n^
Kunihiko Sakamoto 2014/09/12 09:01:02 That's definitely not desirable, but wouldn't be a
+ if (!fontFace)
+ return ScriptValue(scriptState, v8DoneIteratorResult(scriptState->isolate()));
+ m_index++;
+ if (m_kind == FontFaceSetIterator::Entries) {
+ Vector<ScriptValue> entry;
+ ScriptValue value = ScriptValue(scriptState, toV8(fontFace, scriptState->context()->Global(), scriptState->isolate()));
haraken 2014/09/11 12:06:07 yhirano-san: In the Iterator pattern, is it guaran
yhirano 2014/09/11 12:29:06 I think so, next is called just like other methods
haraken 2014/09/11 12:32:28 No :) I just wanted to confirm that we don't need
+ entry.append(value);
+ entry.append(value);
+ return ScriptValue(scriptState, v8IteratorResult(scriptState, entry));
+ }
+ return ScriptValue(scriptState, v8IteratorResult(scriptState, fontFace));
+}
+
} // namespace blink
« no previous file with comments | « Source/core/css/FontFaceSet.h ('k') | Source/core/css/FontFaceSet.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698