gfx/skia/trunk/src/animator/SkDisplayEvents.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkDisplayEvents.h"
michael@0 11 #include "SkAnimateMaker.h"
michael@0 12 #include "SkAnimator.h"
michael@0 13 #include "SkDisplayEvent.h"
michael@0 14 #include "SkDisplayMovie.h"
michael@0 15 #include "SkDrawable.h"
michael@0 16 #ifdef SK_DEBUG
michael@0 17 #include "SkDump.h"
michael@0 18 #endif
michael@0 19
michael@0 20 SkEventState::SkEventState() : fCode(0), fDisable(false), fDisplayable(0), fX(0), fY(0) {
michael@0 21 }
michael@0 22
michael@0 23 SkEvents::SkEvents() {
michael@0 24 }
michael@0 25
michael@0 26 SkEvents::~SkEvents() {
michael@0 27 }
michael@0 28
michael@0 29 bool SkEvents::doEvent(SkAnimateMaker& maker, SkDisplayEvent::Kind kind, SkEventState* state) {
michael@0 30 /*#ifdef SK_DUMP_ENABLED
michael@0 31 if (maker.fDumpEvents) {
michael@0 32 SkDebugf("doEvent: ");
michael@0 33 SkString str;
michael@0 34 SkDump::GetEnumString(SkType_EventKind, kind, &str);
michael@0 35 SkDebugf("kind=%s ", str.c_str());
michael@0 36 if (state && state->fDisplayable)
michael@0 37 state->fDisplayable->SkDisplayable::dump(&maker);
michael@0 38 else
michael@0 39 SkDebugf("\n");
michael@0 40 }
michael@0 41 #endif*/
michael@0 42 bool handled = false;
michael@0 43 SkDisplayable** firstMovie = maker.fMovies.begin();
michael@0 44 SkDisplayable** endMovie = maker.fMovies.end();
michael@0 45 for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) {
michael@0 46 SkDisplayMovie* movie = (SkDisplayMovie*) *ptr;
michael@0 47 if (kind != SkDisplayEvent::kOnload)
michael@0 48 movie->doEvent(kind, state);
michael@0 49 }
michael@0 50 SkDisplayable* displayable = state ? state->fDisplayable : NULL;
michael@0 51 int keyCode = state ? state->fCode : 0;
michael@0 52 int count = fEvents.count();
michael@0 53 for (int index = 0; index < count; index++) {
michael@0 54 SkDisplayEvent* evt = fEvents[index];
michael@0 55 if (evt->disable)
michael@0 56 continue;
michael@0 57 if (evt->kind != kind)
michael@0 58 continue;
michael@0 59 if (evt->code != (SkKey) -1) {
michael@0 60 if ((int) evt->code > keyCode || (int) (evt->fMax != (SkKey) -1 ? evt->fMax : evt->code) < keyCode)
michael@0 61 continue;
michael@0 62 evt->fLastCode = (SkKey) keyCode;
michael@0 63 }
michael@0 64 if (evt->fTarget != NULL && evt->fTarget != displayable)
michael@0 65 continue;
michael@0 66 if (state == NULL || state->fDisable == 0) {
michael@0 67 if (kind >= SkDisplayEvent::kMouseDown && kind <= SkDisplayEvent::kMouseUp) {
michael@0 68 evt->x = state->fX;
michael@0 69 evt->y = state->fY;
michael@0 70 }
michael@0 71 if (evt->enableEvent(maker))
michael@0 72 fError = true;
michael@0 73 }
michael@0 74 handled = true;
michael@0 75 }
michael@0 76 return handled;
michael@0 77 }
michael@0 78
michael@0 79 #ifdef SK_DUMP_ENABLED
michael@0 80 void SkEvents::dump(SkAnimateMaker& maker) {
michael@0 81 int index;
michael@0 82 SkTDDrawableArray& drawArray = maker.fDisplayList.fDrawList;
michael@0 83 int count = drawArray.count();
michael@0 84 for (index = 0; index < count; index++) {
michael@0 85 SkDrawable* drawable = drawArray[index];
michael@0 86 drawable->dumpEvents();
michael@0 87 }
michael@0 88 count = fEvents.count();
michael@0 89 for (index = 0; index < count; index++) {
michael@0 90 SkDisplayEvent* evt = fEvents[index];
michael@0 91 evt->dumpEvent(&maker);
michael@0 92 }
michael@0 93 }
michael@0 94 #endif
michael@0 95
michael@0 96 // currently this only removes onLoad events
michael@0 97 void SkEvents::removeEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
michael@0 98 int keyCode = state ? state->fCode : 0;
michael@0 99 SkDisplayable* displayable = state ? state->fDisplayable : NULL;
michael@0 100 for (SkDisplayEvent** evtPtr = fEvents.begin(); evtPtr < fEvents.end(); evtPtr++) {
michael@0 101 SkDisplayEvent* evt = *evtPtr;
michael@0 102 if (evt->kind != kind)
michael@0 103 continue;
michael@0 104 if (evt->code != (SkKey) -1) {
michael@0 105 if ((int) evt->code > keyCode || (int) (evt->fMax != (SkKey) -1 ? evt->fMax : evt->code) < keyCode)
michael@0 106 continue;
michael@0 107 }
michael@0 108 if (evt->fTarget != NULL && evt->fTarget != displayable)
michael@0 109 continue;
michael@0 110 int index = fEvents.find(evt);
michael@0 111 fEvents.remove(index);
michael@0 112 }
michael@0 113 }

mercurial