SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { return NULL; } if (this->onSendClickToChildren(x, y, modi)) { F2BIter iter(this); SkView* child; while ((child = iter.next()) != NULL) { SkPoint p; if (!child->globalToLocal(x, y, &p)) { continue; } Click* click = child->findClickHandler(p.fX, p.fY, modi); if (click) { return click; } } } return this->onFindClickHandler(x, y, modi); }
void SampleWindow::updateTitle() { SkString title; SkView::F2BIter iter(this); SkView* view = iter.next(); SkEvent evt(gTitleEvtName); if (view->doQuery(&evt)) { title.set(evt.findString(gTitleEvtName)); } if (title.size() == 0) { title.set("<unknown>"); } title.prepend(gCanvasTypePrefix[fCanvasType]); title.prepend(" "); title.prepend(configToString(this->getBitmap().config())); if (fAnimating) { title.prepend("<A> "); } if (fScale) { title.prepend("<S> "); } if (fRotate) { title.prepend("<R> "); } if (fNClip) { title.prepend("<C> "); } this->setTitle(title.c_str()); }
bool SkWindow::handleKey(SkKey key) { if (key == kNONE_SkKey) return false; if (this->onHandleKey(key)) return true; // send an event to the focus-view { SkView* focus = this->getFocusView(); if (focus == nullptr) focus = this; SkEvent evt(SK_EventType_Key); evt.setFast32(key); if (focus->doEvent(evt)) return true; } if (key == kUp_SkKey || key == kDown_SkKey) { if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_FocusDirection) == nullptr) this->onSetFocusView(nullptr); return true; } return false; }
SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { return nullptr; } if (this->onSendClickToChildren(x, y, modi)) { F2BIter iter(this); SkView* child; while ((child = iter.next()) != nullptr) { SkPoint p; #if 0 if (!child->globalToLocal(x, y, &p)) { continue; } #else // the above seems broken, so just respecting fLoc for now <reed> p.set(x - child->fLoc.x(), y - child->fLoc.y()); #endif Click* click = child->findClickHandler(p.fX, p.fY, modi); if (click) { return click; } } } return this->onFindClickHandler(x, y, modi); }
void SkView::inval(SkRect* rect) { SkView* view = this; SkRect storage; for (;;) { if (!view->isVisible()) { return; } if (view->isClipToBounds()) { SkRect bounds; view->getLocalBounds(&bounds); if (rect && !bounds.intersect(*rect)) { return; } storage = bounds; rect = &storage; } if (view->handleInval(rect)) { return; } SkView* parent = view->fParent; if (parent == NULL) { return; } if (rect) { rect->offset(view->fLoc.fX, view->fLoc.fY); } view = parent; } }
virtual bool onEvent(const SkEvent& evt) { if (evt.isType(gReplaceTransitionEvt)) { SkView* prev = fPrev; prev->ref(); fPrev->detachFromParent(); fPrev = (SkView*)SkEventSink::FindSink(evt.getFast32()); (void)SampleView::SetUsePipe(fPrev, SkOSMenu::kOffState); //attach the new fPrev and call unref to balance the ref in onDraw this->attachChildToBack(fPrev)->unref(); this->inval(NULL); SkASSERT(1 == prev->getRefCnt()); prev->unref(); return true; } if (evt.isType("transition-done")) { fNext->setLoc(0, 0); fNext->setClipToBounds(false); SkEvent* evt = new SkEvent(gReplaceTransitionEvt, this->getParent()->getSinkID()); evt->setFast32(fNext->getSinkID()); //increate ref count of fNext so it survives detachAllChildren fNext->ref(); this->detachAllChildren(); evt->post(); return true; } return this->INHERITED::onEvent(evt); }
void SkView::postInflate(const SkTDict<SkView*>& dict) { this->onPostInflate(dict); B2FIter iter(this); SkView* child; while ((child = iter.next()) != nullptr) child->postInflate(dict); }
void SkView::detachFromParent() { this->validate(); SkView* parent = fParent; if (parent) { this->detachFromParent_NoLayout(); parent->invokeLayout(); } }
bool SkView::setFocusView(SkView* fv) { SkView* view = this; do { if (view->onSetFocusView(fv)) return true; } while ((view = view->fParent) != NULL); return false; }
const char* State::getSlideTitle(int index) const { SkEvent evt(gTitleEvtName); evt.setFast32(index); { SkView* view = fFactory[index](); view->doQuery(&evt); view->unref(); } return evt.findString(gTitleEvtName); }
SkView* SkView::sendEventToParents(const SkEvent& evt) { SkView* parent = fParent; while (parent) { if (parent->doEvent(evt)) { return parent; } parent = parent->fParent; } return nullptr; }
SkView* SkView::moveFocus(FocusDirection dir) { SkView* focus = this->getFocusView(); if (focus == nullptr) { // start with the root focus = this; while (focus->fParent) { focus = focus->fParent; } } SkView* child, *parent; if (dir == kNext_FocusDirection) { parent = focus; child = focus->fFirstChild; if (child) goto FIRST_CHILD; else goto NEXT_SIB; do { while (child != parent->fFirstChild) { FIRST_CHILD: if ((focus = child->acceptFocus(dir)) != nullptr) return focus; child = child->fNextSibling; } NEXT_SIB: child = parent->fNextSibling; parent = parent->fParent; } while (parent != nullptr); } else { // prevfocus parent = focus->fParent; if (parent == nullptr) { // we're the root return focus->acceptFocus(dir); } else { child = focus; while (parent) { while (child != parent->fFirstChild) { child = child->fPrevSibling; if ((focus = child->acceptFocus(dir)) != nullptr) { return focus; } } if (parent->acceptFocus()) { return parent; } child = parent; parent = parent->fParent; } } } return nullptr; }
SkView* SkView::sendQueryToParents(SkEvent* evt) { SkView* parent = fParent; while (parent) { if (parent->doQuery(evt)) { return parent; } parent = parent->fParent; } return NULL; }
SkView* SkView::sendEventToParents(const SkEvent& evt) { SkView* parent = fParent; while (parent) { if (parent->doEvent(evt)) return parent; parent = parent->fParent; } return NULL; }
void SkFillViewLayout::onLayoutChildren(SkView* parent) { SkView::B2FIter iter(parent); SkView* child; while ((child = iter.next()) != nullptr) { child->setLoc(fMargin.fLeft, fMargin.fTop); child->setSize( parent->width() - fMargin.fRight - fMargin.fLeft, parent->height() - fMargin.fBottom - fMargin.fTop); } }
bool SkWindow::handleChar(SkUnichar uni) { if (this->onHandleChar(uni)) return true; SkView* focus = this->getFocusView(); if (focus == NULL) focus = this; SkEvent evt(SK_EventType_Unichar); evt.setFast32(uni); return focus->doEvent(evt); }
void State::setViewport(int w, int h) { fViewport.set(w, h); if (fView) { fView->setSize(SkIntToScalar(w), SkIntToScalar(h)); } resetGpuState(); }
void SampleWindow::loadView(SkView* view) { SkView::F2BIter iter(this); SkView* prev = iter.next(); if (prev) { prev->detachFromParent(); } if (NULL == view) { view = create_overview(fSamples.count(), fSamples.begin()); } view->setVisibleP(true); this->attachChildToFront(view)->unref(); view->setSize(this->width(), this->height()); this->updateTitle(); }
void SkView::DoClickUp(Click* click, int x, int y) { SkASSERT(click); SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); if (target == NULL) return; click->fIPrev = click->fICurr; click->fICurr.set(x, y); click->fPrev = click->fCurr; click->fCurr.iset(x, y); target->globalToLocal(&click->fCurr); click->fState = Click::kUp_State; target->onClick(click); }
void OverView::onSizeChange() { this->detachAllChildren(); SkScalar locX = 0; SkScalar locY = 0; for (int i = 0; i < fCount; i++) { SkView* view = (*fFactories[i])(); view->setVisibleP(true); this->attachChildToBack(view)->unref(); view->setLoc(locX, locY); view->setSize(W, H); locX += W; if ((i % N) == N - 1) { locY += H; locX = 0; } } }
void SkView::draw(SkCanvas* canvas) { if (fWidth && fHeight && this->isVisible()) { SkRect r; r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); if (this->isClipToBounds() && canvas->quickReject(r)) { return; } SkAutoCanvasRestore as(canvas, true); if (this->isClipToBounds()) { canvas->clipRect(r); } canvas->translate(fLoc.fX, fLoc.fY); canvas->concat(fMatrix); if (fParent) { fParent->beforeChild(this, canvas); } int sc = canvas->save(); this->onDraw(canvas); canvas->restoreToCount(sc); if (fParent) { fParent->afterChild(this, canvas); } B2FIter iter(this); SkView* child; SkCanvas* childCanvas = this->beforeChildren(canvas); while ((child = iter.next()) != nullptr) child->draw(childCanvas); this->afterChildren(canvas); } }
SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y) { if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { return false; } if (this->onSendClickToChildren(x, y)) { F2BIter iter(this); SkView* child; while ((child = iter.next()) != NULL) { Click* click = child->findClickHandler(x - child->fLoc.fX, y - child->fLoc.fY); if (click) { return click; } } } return this->onFindClickHandler(x, y); }
bool SkWindow::handleKeyUp(SkKey key) { if (key == kNONE_SkKey) return false; if (this->onHandleKeyUp(key)) return true; //send an event to the focus-view { SkView* focus = this->getFocusView(); if (focus == NULL) focus = this; //should this one be the same? SkEvent evt(SK_EventType_KeyUp); evt.setFast32(key); if (focus->doEvent(evt)) return true; } return false; }
void SkView::DoClickUp(Click* click, int x, int y) { SkASSERT(click); SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); if (NULL == target) { return; } click->fIPrev = click->fICurr; click->fICurr.set(x, y); click->fPrev = click->fCurr; click->fCurr.iset(x, y); if (!target->globalToLocal(&click->fCurr)) { // on failure pretend the mouse didn't move click->fCurr = click->fPrev; } click->fState = Click::kUp_State; target->onClick(click); }
/* Measure the main-dimension for all the children. If a child is marked flex in that direction ignore its current value but increment the counter for flexChildren */ static SkScalar compute_children_limit(SkView* parent, GetSizeProc sizeProc, int* count, uint32_t flexMask, int* flexCount) { SkView::B2FIter iter(parent); SkView* child; SkScalar limit = 0; int n = 0, flex = 0; while ((child = iter.next()) != nullptr) { n += 1; if (child->getFlags() & flexMask) flex += 1; else limit += (child->*sizeProc)(); } if (count) *count = n; if (flexCount) *flexCount = flex; return limit; }
void SkView::DoClickDown(Click* click, int x, int y) { SkASSERT(click); SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); if (NULL == target) { return; } click->fIOrig.set(x, y); click->fICurr = click->fIPrev = click->fIOrig; click->fOrig.iset(x, y); if (!target->globalToLocal(&click->fOrig)) { // no history to let us recover from this failure return; } click->fPrev = click->fCurr = click->fOrig; click->fState = Click::kDown_State; target->onClick(click); }
SkView* SkViewInflate::inflate(const SkDOM& dom, const SkDOM::Node* node, SkView* root) { fIDs.reset(); if (root == NULL) { root = this->createView(dom, node); if (root == NULL) { printf("createView returned NULL on <%s>\n", dom.getName(node)); return NULL; } } this->rInflate(dom, node, root); // resolve listeners and broadcasters { SkView* target; const IDStr* iter = fListenTo.begin(); const IDStr* stop = fListenTo.end(); for (; iter < stop; iter++) { if (fIDs.find(iter->fStr, &target)) target->addListenerID(iter->fView->getSinkID()); } iter = fBroadcastTo.begin(); stop = fBroadcastTo.end(); for (; iter < stop; iter++) { if (fIDs.find(iter->fStr, &target)) iter->fView->addListenerID(target->getSinkID()); } } // now that the tree is built, give everyone a shot at the ID dict root->postInflate(fIDs); return root; }
void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) { SkASSERT(click); SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); if (nullptr == target) { return; } click->fIPrev = click->fICurr; click->fICurr.set(x, y); click->fPrev = click->fCurr; click->fCurr.iset(x, y); if (!target->globalToLocal(&click->fCurr)) { // on failure pretend the mouse didn't move click->fCurr = click->fPrev; } click->fState = Click::kMoved_State; click->fModifierKeys = modi; target->onClick(click); }
void SkView::draw(SkCanvas* canvas) { if (fWidth && fHeight && this->isVisible()) { SkRect r; r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); if (canvas->quickReject(r, SkCanvas::kBW_EdgeType)) return; SkAutoCanvasRestore as(canvas, true); canvas->clipRect(r); canvas->translate(fLoc.fX, fLoc.fY); if (fParent) { fParent->beforeChild(this, canvas); } int sc = canvas->save(); this->onDraw(canvas); canvas->restoreToCount(sc); if (fParent) { fParent->afterChild(this, canvas); } B2FIter iter(this); SkView* child; SkCanvas* childCanvas = this->beforeChildren(canvas); while ((child = iter.next()) != NULL) child->draw(childCanvas); this->afterChildren(canvas); } }
void SkStackViewLayout::onLayoutChildren(SkView* parent) { static AlignProc gAlignProcs[] = { left_align_proc, center_align_proc, right_align_proc, fill_align_proc }; SkScalar startM, endM, crossStartM, crossLimit; GetSizeProc mainGetSizeP, crossGetSizeP; SetLocProc mainLocP, crossLocP; SetSizeProc mainSetSizeP, crossSetSizeP; SkView::Flag_Mask flexMask; if (fOrient == kHorizontal_Orient) { startM = fMargin.fLeft; endM = fMargin.fRight; crossStartM = fMargin.fTop; crossLimit = -fMargin.fTop - fMargin.fBottom; mainGetSizeP = &SkView::width; crossGetSizeP = &SkView::height; mainLocP = &SkView::setLocX; crossLocP = &SkView::setLocY; mainSetSizeP = &SkView::setWidth; crossSetSizeP = &SkView::setHeight; flexMask = SkView::kFlexH_Mask; } else { startM = fMargin.fTop; endM = fMargin.fBottom; crossStartM = fMargin.fLeft; crossLimit = -fMargin.fLeft - fMargin.fRight; mainGetSizeP = &SkView::height; crossGetSizeP = &SkView::width; mainLocP = &SkView::setLocY; crossLocP = &SkView::setLocX; mainSetSizeP = &SkView::setHeight; crossSetSizeP = &SkView::setWidth; flexMask = SkView::kFlexV_Mask; } crossLimit += (parent->*crossGetSizeP)(); if (fAlign != kStretch_Align) crossSetSizeP = nullptr; int childCount, flexCount; SkScalar childLimit = compute_children_limit(parent, mainGetSizeP, &childCount, flexMask, &flexCount); if (childCount == 0) return; childLimit += (childCount - 1) * fSpacer; SkScalar parentLimit = (parent->*mainGetSizeP)() - startM - endM; SkScalar pos = startM + gAlignProcs[fPack](childLimit, parentLimit); SkScalar flexAmount = 0; SkView::B2FIter iter(parent); SkView* child; if (flexCount > 0 && parentLimit > childLimit) flexAmount = (parentLimit - childLimit) / flexCount; while ((child = iter.next()) != nullptr) { if (fRound) pos = SkScalarRoundToScalar(pos); (child->*mainLocP)(pos); SkScalar crossLoc = crossStartM + gAlignProcs[fAlign]((child->*crossGetSizeP)(), crossLimit); if (fRound) crossLoc = SkScalarRoundToScalar(crossLoc); (child->*crossLocP)(crossLoc); if (crossSetSizeP) (child->*crossSetSizeP)(crossLimit); if (child->getFlags() & flexMask) (child->*mainSetSizeP)(flexAmount); pos += (child->*mainGetSizeP)() + fSpacer; } }