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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 380
381 for (size_t i = 0; i < fontFaces.size(); ++i) { 381 for (size_t i = 0; i < fontFaces.size(); ++i) {
382 FontFace* face = fontFaces[i].get(); 382 FontFace* face = fontFaces[i].get();
383 if (thisArg) 383 if (thisArg)
384 callback->handleItem(*thisArg, face, face, const_cast<FontFaceSet*>( this)); 384 callback->handleItem(*thisArg, face, face, const_cast<FontFaceSet*>( this));
385 else 385 else
386 callback->handleItem(face, face, const_cast<FontFaceSet*>(this)); 386 callback->handleItem(face, face, const_cast<FontFaceSet*>(this));
387 } 387 }
388 } 388 }
389 389
390 Iterator* FontFaceSet::keys()
391 {
392 return new FontFaceSetIterator(this, FontFaceSetIterator::Keys);
393 }
394
395 Iterator* FontFaceSet::values()
396 {
397 return new FontFaceSetIterator(this, FontFaceSetIterator::Values);
398 }
399
400 Iterator* FontFaceSet::entries()
401 {
402 return new FontFaceSetIterator(this, FontFaceSetIterator::Entries);
403 }
404
390 unsigned long FontFaceSet::size() const 405 unsigned long FontFaceSet::size() const
391 { 406 {
392 if (!inActiveDocumentContext()) 407 if (!inActiveDocumentContext())
393 return m_nonCSSConnectedFaces.size(); 408 return m_nonCSSConnectedFaces.size();
394 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size(); 409 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size();
395 } 410 }
396 411
412 FontFace* FontFaceSet::fontFaceAt(size_t index) const
413 {
414 if (inActiveDocumentContext()) {
415 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& cssConnected Faces = cssConnectedFontFaceList();
416 if (index < cssConnectedFaces.size()) {
417 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::const_iterator it = cssConnectedFaces.begin();
418 for (size_t i = 0; i < index; i++)
419 ++it;
420 return it->get();
421 }
422 index -= cssConnectedFaces.size();
423 }
424 if (index < m_nonCSSConnectedFaces.size()) {
425 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::const_iterator it = m_nonCSSConnectedFaces.begin();
426 for (size_t i = 0; i < index; i++)
427 ++it;
428 return it->get();
429 }
430 return 0;
431 }
432
397 void FontFaceSet::fireDoneEventIfPossible() 433 void FontFaceSet::fireDoneEventIfPossible()
398 { 434 {
399 if (m_shouldFireLoadingEvent) 435 if (m_shouldFireLoadingEvent)
400 return; 436 return;
401 if (!m_loadingFonts.isEmpty() || (!hasLoadedFonts() && m_readyResolvers.isEm pty())) 437 if (!m_loadingFonts.isEmpty() || (!hasLoadedFonts() && m_readyResolvers.isEm pty()))
402 return; 438 return;
403 439
404 // If the layout was invalidated in between when we thought layout 440 // If the layout was invalidated in between when we thought layout
405 // was updated and when we're ready to fire the event, just wait 441 // was updated and when we're ready to fire the event, just wait
406 // until after the next layout before firing events. 442 // until after the next layout before firing events.
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 { 621 {
586 visitor->trace(m_loadingFonts); 622 visitor->trace(m_loadingFonts);
587 visitor->trace(m_loadedFonts); 623 visitor->trace(m_loadedFonts);
588 visitor->trace(m_failedFonts); 624 visitor->trace(m_failedFonts);
589 visitor->trace(m_nonCSSConnectedFaces); 625 visitor->trace(m_nonCSSConnectedFaces);
590 DocumentSupplement::trace(visitor); 626 DocumentSupplement::trace(visitor);
591 EventTargetWithInlineData::trace(visitor); 627 EventTargetWithInlineData::trace(visitor);
592 } 628 }
593 #endif 629 #endif
594 630
631 ScriptValue FontFaceSet::FontFaceSetIterator::next(ScriptState* scriptState, Exc eptionState&)
632 {
633 FontFace* fontFace = m_fontFaceSet->fontFaceAt(m_index);
634 if (!fontFace)
635 return ScriptValue(scriptState, v8DoneIteratorResult(scriptState->isolat e()));
636 m_index++;
637 if (m_kind == FontFaceSetIterator::Entries) {
638 Vector<ScriptValue> entry;
639 ScriptValue value = ScriptValue(scriptState, V8ValueTraits<FontFace*>::t oV8Value(fontFace, scriptState->context()->Global(), scriptState->isolate()));
yhirano 2014/09/11 08:04:45 You can include bindings/core/v8/V8FontFaceSet.h a
Kunihiko Sakamoto 2014/09/11 10:47:35 Ah good to know. Thanks.
640 entry.append(value);
641 entry.append(value);
642 return ScriptValue(scriptState, v8IteratorResult(scriptState, entry));
643 }
644 return ScriptValue(scriptState, v8IteratorResult(scriptState, fontFace));
645 }
646
595 } // namespace blink 647 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698