180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc. 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkView.h" 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//////////////////////////////////////////////////////////////////////// 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWidth = fHeight = 0; 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fLoc.set(0, 0); 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent = fFirstChild = fNextSibling = fPrevSibling = NULL; 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMatrix.setIdentity(); 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fContainsFocus = 0; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView::~SkView() 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->detachAllChildren(); 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setFlags(uint32_t flags) 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT((flags & ~kAllFlagMasks) == 0); 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint32_t diff = fFlags ^ flags; 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (diff & kVisible_Mask) 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFlags = SkToU8(flags); 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (diff & kVisible_Mask) 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setVisibleP(bool pred) 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift)); 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setEnabledP(bool pred) 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift)); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setFocusableP(bool pred) 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setClipToBounds(bool pred) { 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setSize(SkScalar width, SkScalar height) 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru width = SkMaxScalar(0, width); 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru height = SkMaxScalar(0, height); 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fWidth != width || fHeight != height) 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWidth = width; 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fHeight = height; 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->onSizeChange(); 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->invokeLayout(); 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setLoc(SkScalar x, SkScalar y) 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fLoc.fX != x || fLoc.fY != y) 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fLoc.set(x, y); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::offset(SkScalar dx, SkScalar dy) 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (dx || dy) 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setLoc(fLoc.fX + dx, fLoc.fY + dy); 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::setLocalMatrix(const SkMatrix& matrix) 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMatrix = matrix; 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::draw(SkCanvas* canvas) 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fWidth && fHeight && this->isVisible()) 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRect r; 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (this->isClipToBounds() && 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->quickReject(r)) { 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAutoCanvasRestore as(canvas, true); 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (this->isClipToBounds()) { 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->clipRect(r); 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->translate(fLoc.fX, fLoc.fY); 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->concat(fMatrix); 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fParent) { 12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent->beforeChild(this, canvas); 12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int sc = canvas->save(); 12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->onDraw(canvas); 12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->restoreToCount(sc); 12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fParent) { 13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent->afterChild(this, canvas); 13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru B2FIter iter(this); 13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child; 13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkCanvas* childCanvas = this->beforeChildren(canvas); 13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while ((child = iter.next()) != NULL) 14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->draw(childCanvas); 14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->afterChildren(canvas); 14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::inval(SkRect* rect) { 14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* view = this; 14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRect storage; 14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (;;) { 15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!view->isVisible()) { 15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (view->isClipToBounds()) { 15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRect bounds; 15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru view->getLocalBounds(&bounds); 15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rect && !bounds.intersect(*rect)) { 15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru storage = bounds; 16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rect = &storage; 16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (view->handleInval(rect)) { 16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* parent = view->fParent; 16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (parent == NULL) { 16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rect) { 17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rect->offset(view->fLoc.fX, view->fLoc.fY); 17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru view = parent; 17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//////////////////////////////////////////////////////////////////////////// 18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::setFocusView(SkView* fv) 18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* view = this; 18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru do { 18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (view->onSetFocusView(fv)) 18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } while ((view = view->fParent) != NULL); 18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView* SkView::getFocusView() const 19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* focus = NULL; 19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkView* view = this; 19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru do { 19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (view->onGetFocusView(&focus)) 19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } while ((view = view->fParent) != NULL); 20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return focus; 20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::hasFocus() const 20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this == this->getFocusView(); 20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::acceptFocus() 20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->isFocusable() && this->setFocusView(this); 21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Try to give focus to this view, or its children 21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/ 21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView* SkView::acceptFocus(FocusDirection dir) 21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (dir == kNext_FocusDirection) 21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (this->acceptFocus()) 22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this; 22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru B2FIter iter(this); 22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child, *focus; 22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while ((child = iter.next()) != NULL) 22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if ((focus = child->acceptFocus(dir)) != NULL) 22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return focus; 22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else // prev 23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru F2BIter iter(this); 23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child, *focus; 23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while ((child = iter.next()) != NULL) 23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if ((focus = child->acceptFocus(dir)) != NULL) 23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return focus; 23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (this->acceptFocus()) 23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this; 23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView* SkView::moveFocus(FocusDirection dir) 24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* focus = this->getFocusView(); 24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (focus == NULL) 24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { // start with the root 25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru focus = this; 25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (focus->fParent) 25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru focus = focus->fParent; 25380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child, *parent; 25680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (dir == kNext_FocusDirection) 25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent = focus; 26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child = focus->fFirstChild; 26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (child) 26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto FIRST_CHILD; 26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto NEXT_SIB; 26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru do { 26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (child != parent->fFirstChild) 26880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 26980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru FIRST_CHILD: 27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if ((focus = child->acceptFocus(dir)) != NULL) 27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return focus; 27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child = child->fNextSibling; 27380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru NEXT_SIB: 27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child = parent->fNextSibling; 27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent = parent->fParent; 27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } while (parent != NULL); 27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else // prevfocus 28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent = focus->fParent; 28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (parent == NULL) // we're the root 28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return focus->acceptFocus(dir); 28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 28580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 28680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child = focus; 28780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (parent) 28880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 28980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (child != parent->fFirstChild) 29080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 29180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child = child->fPrevSibling; 29280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if ((focus = child->acceptFocus(dir)) != NULL) 29380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return focus; 29480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 29580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (parent->acceptFocus()) 29680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return parent; 29780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 29880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child = parent; 29980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent = parent->fParent; 30080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 30180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 30280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 30380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 30480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 30580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::onFocusChange(bool gainFocusP) 30780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 30880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 30980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 31080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 31180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//////////////////////////////////////////////////////////////////////////// 31280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 31380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView::Click::Click(SkView* target) 31480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 31580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(target); 31680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTargetID = target->getSinkID(); 31780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fType = NULL; 31880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWeOwnTheType = false; 31980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fOwner = NULL; 32080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 32180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView::Click::~Click() 32380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 32480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->resetType(); 32580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 32680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::Click::resetType() 32880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 32980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fWeOwnTheType) 33080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 33180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru sk_free(fType); 33280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWeOwnTheType = false; 33380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 33480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fType = NULL; 33580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 33680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 33780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::Click::isType(const char type[]) const 33880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 33980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* t = fType; 34080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 34180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (type == t) 34280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 34380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 34480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (type == NULL) 34580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru type = ""; 34680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (t == NULL) 34780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru t = ""; 34880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return !strcmp(t, type); 34980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 35080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 35180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::Click::setType(const char type[]) 35280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 35380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->resetType(); 35480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fType = (char*)type; 35580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 35680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 35780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::Click::copyType(const char type[]) 35880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 35980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fType != type) 36080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 36180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->resetType(); 36280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (type) 36380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 36480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru size_t len = strlen(type) + 1; 36580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fType = (char*)sk_malloc_throw(len); 36680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru memcpy(fType, type, len); 36780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fWeOwnTheType = true; 36880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 36980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 37080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 37180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 372d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek SollenbergerSkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { 37380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { 37480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 37580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 37680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 377d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger if (this->onSendClickToChildren(x, y, modi)) { 37880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru F2BIter iter(this); 37980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child; 38080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 38180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while ((child = iter.next()) != NULL) 38280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 38380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPoint p; 38480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!child->globalToLocal(x, y, &p)) { 38580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru continue; 38680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 38780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 388d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger Click* click = child->findClickHandler(p.fX, p.fY, modi); 38980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 39080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (click) { 39180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return click; 39280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 39380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 39480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 39580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 396d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger return this->onFindClickHandler(x, y, modi); 39780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 39880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 399d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenbergervoid SkView::DoClickDown(Click* click, int x, int y, unsigned modi) 40080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 40180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(click); 40280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 40380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); 40480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL == target) { 40580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 40680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 40780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 40880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fIOrig.set(x, y); 40980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fICurr = click->fIPrev = click->fIOrig; 41080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 41180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fOrig.iset(x, y); 41280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!target->globalToLocal(&click->fOrig)) { 41380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // no history to let us recover from this failure 41480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 41580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 41680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fPrev = click->fCurr = click->fOrig; 41780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 41880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fState = Click::kDown_State; 419d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger click->fModifierKeys = modi; 42080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru target->onClick(click); 42180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 42280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 423d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenbergervoid SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) 42480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 42580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(click); 42680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 42780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); 42880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL == target) { 42980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 43080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 43180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 43280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fIPrev = click->fICurr; 43380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fICurr.set(x, y); 43480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 43580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fPrev = click->fCurr; 43680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fCurr.iset(x, y); 43780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!target->globalToLocal(&click->fCurr)) { 43880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // on failure pretend the mouse didn't move 43980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fCurr = click->fPrev; 44080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 44180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 44280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fState = Click::kMoved_State; 443d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger click->fModifierKeys = modi; 44480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru target->onClick(click); 44580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 44680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 447d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenbergervoid SkView::DoClickUp(Click* click, int x, int y, unsigned modi) 44880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 44980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(click); 45080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 45180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); 45280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL == target) { 45380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 45480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 45580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 45680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fIPrev = click->fICurr; 45780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fICurr.set(x, y); 45880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 45980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fPrev = click->fCurr; 46080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fCurr.iset(x, y); 46180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!target->globalToLocal(&click->fCurr)) { 46280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // on failure pretend the mouse didn't move 46380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fCurr = click->fPrev; 46480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 46580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 46680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru click->fState = Click::kUp_State; 467d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger click->fModifierKeys = modi; 46880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru target->onClick(click); 46980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 47080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 47180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////// 47280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 47380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::invokeLayout() { 47480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView::Layout* layout = this->getLayout(); 47580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 47680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (layout) { 47780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru layout->layoutChildren(this); 47880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 47980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 48080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 48180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::onDraw(SkCanvas* canvas) { 48280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Artist* artist = this->getArtist(); 48380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 48480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (artist) { 48580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru artist->draw(this, canvas); 48680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 48780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 48880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 48980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::onSizeChange() {} 49080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 491d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenbergerbool SkView::onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) { 49280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 49380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 49480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 495d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek SollenbergerSkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) { 49680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 49780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 49880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 49980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::onClick(Click*) { 50080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 50180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 50280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 50380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::handleInval(const SkRect*) { 50480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 50580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 50680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 50780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////// 50880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 50958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::getLocalBounds(SkRect* bounds) const { 51058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (bounds) { 51180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bounds->set(0, 0, fWidth, fHeight); 51258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 51380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 51480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 51580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////// 51680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////// 51780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 51858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::detachFromParent_NoLayout() { 51958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 52058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fParent == NULL) { 52180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 52258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 52380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 52458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fContainsFocus) { 52580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->setFocusView(NULL); 52658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 52780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 52880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->inval(NULL); 52980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 53058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger SkView* next = NULL; 53180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 53258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fNextSibling != this) { // do we have any siblings 53380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fNextSibling->fPrevSibling = fPrevSibling; 53480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fPrevSibling->fNextSibling = fNextSibling; 53580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru next = fNextSibling; 53680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 53780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 53858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fParent->fFirstChild == this) { 53980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent->fFirstChild = next; 54058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 54180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 54280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fParent = fNextSibling = fPrevSibling = NULL; 54380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 54458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 54580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->unref(); 54680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 54780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 54858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::detachFromParent() { 54958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 55080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* parent = fParent; 55180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 55258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (parent) { 55380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->detachFromParent_NoLayout(); 55480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent->invokeLayout(); 55580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 55680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 55780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 55858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView* SkView::attachChildToBack(SkView* child) { 55958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 56080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(child != this); 56180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 56280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (child == NULL || fFirstChild == child) 56380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto DONE; 56480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 56580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->ref(); 56680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->detachFromParent_NoLayout(); 56780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 56858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fFirstChild == NULL) { 56980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fNextSibling = child; 57080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fPrevSibling = child; 57158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } else { 57280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fNextSibling = fFirstChild; 57380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fPrevSibling = fFirstChild->fPrevSibling; 57480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild->fPrevSibling->fNextSibling = child; 57580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild->fPrevSibling = child; 57680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 57780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 57880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild = child; 57980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fParent = this; 58080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->inval(NULL); 58180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 58258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 58380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->invokeLayout(); 58480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDONE: 58580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return child; 58680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 58780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 58858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView* SkView::attachChildToFront(SkView* child) { 58958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 59080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(child != this); 59180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 59280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (child == NULL || (fFirstChild && fFirstChild->fPrevSibling == child)) 59380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto DONE; 59480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 59580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->ref(); 59680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->detachFromParent_NoLayout(); 59780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 59858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fFirstChild == NULL) { 59980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild = child; 60080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fNextSibling = child; 60180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fPrevSibling = child; 60258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } else { 60380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fNextSibling = fFirstChild; 60480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fPrevSibling = fFirstChild->fPrevSibling; 60580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild->fPrevSibling->fNextSibling = child; 60680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild->fPrevSibling = child; 60780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 60880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 60980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->fParent = this; 61080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->inval(NULL); 61180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 61258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 61380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->invokeLayout(); 61480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDONE: 61580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return child; 61680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 61780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 61858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::detachAllChildren() { 61958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger this->validate(); 62080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (fFirstChild) 62180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild->detachFromParent_NoLayout(); 62280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 62380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 62458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::localToGlobal(SkMatrix* matrix) const { 62580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (matrix) { 62680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru matrix->reset(); 62780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkView* view = this; 62880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (view) 62980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 63080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru matrix->preConcat(view->getLocalMatrix()); 63180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru matrix->preTranslate(-view->fLoc.fX, -view->fLoc.fY); 63280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru view = view->fParent; 63380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 63480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 63580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 63680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const 63780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 63880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(this); 63980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 64080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL != local) { 64180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMatrix m; 64280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->localToGlobal(&m); 64380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!m.invert(&m)) { 64480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 64580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 64680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPoint p; 64780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru m.mapXY(x, y, &p); 64880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru local->set(p.fX, p.fY); 64980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 65080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 65180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 65280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 65380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 65480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////// 65580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 65680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* Even if the subclass overrides onInflate, they should always be 65780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru sure to call the inherited method, so that we get called. 65880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/ 65958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node) { 66080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar x, y; 66180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 66280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru x = this->locX(); 66380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru y = this->locY(); 66480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)dom.findScalar(node, "x", &x); 66580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)dom.findScalar(node, "y", &y); 66680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setLoc(x, y); 66780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 66880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru x = this->width(); 66980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru y = this->height(); 67080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)dom.findScalar(node, "width", &x); 67180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)dom.findScalar(node, "height", &y); 67280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setSize(x, y); 67380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 67480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // inflate the flags 67580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 67680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static const char* gFlagNames[] = { 67780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru "visible", "enabled", "focusable", "flexH", "flexV" 67880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 67980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount); 68080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 68180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool b; 68280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint32_t flags = this->getFlags(); 68380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++) 68480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (dom.findBool(node, gFlagNames[i], &b)) 68580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru flags = SkSetClearShift(flags, b, i); 68680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->setFlags(flags); 68780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 68880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 68958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::inflate(const SkDOM& dom, const SkDOM::Node* node) { 69080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->onInflate(dom, node); 69180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 69280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 69358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::onPostInflate(const SkTDict<SkView*>&) { 69480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // override in subclass as needed 69580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 69680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 69758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::postInflate(const SkTDict<SkView*>& dict) { 69880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->onPostInflate(dict); 69980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 70080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru B2FIter iter(this); 70180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child; 70280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while ((child = iter.next()) != NULL) 70380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru child->postInflate(dict); 70480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 70580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 70680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////// 70780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 70858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView* SkView::sendEventToParents(const SkEvent& evt) { 70980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* parent = fParent; 71080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 71158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger while (parent) { 71258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (parent->doEvent(evt)) { 71380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return parent; 71458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 71580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent = parent->fParent; 71680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 71780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 71880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 71980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 72080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkView* SkView::sendQueryToParents(SkEvent* evt) { 72180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* parent = fParent; 72280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 72380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (parent) { 72480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (parent->doQuery(evt)) { 72580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return parent; 72680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 72780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent = parent->fParent; 72880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 72980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 73080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 73180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 73280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////// 73380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////// 73480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 73558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView::F2BIter::F2BIter(const SkView* parent) { 73680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild = parent ? parent->fFirstChild : NULL; 73780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fChild = fFirstChild ? fFirstChild->fPrevSibling : NULL; 73880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 73980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 74058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView* SkView::F2BIter::next() { 74180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* curr = fChild; 74280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 74358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fChild) { 74458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fChild == fFirstChild) { 74580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fChild = NULL; 74658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } else { 74780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fChild = fChild->fPrevSibling; 74858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 74980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 75080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return curr; 75180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 75280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 75358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView::B2FIter::B2FIter(const SkView* parent) { 75480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fFirstChild = parent ? parent->fFirstChild : NULL; 75580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fChild = fFirstChild; 75680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 75780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 75858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkView* SkView::B2FIter::next() { 75980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* curr = fChild; 76080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 76158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fChild) { 76280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* next = fChild->fNextSibling; 76380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (next == fFirstChild) 76480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru next = NULL; 76580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fChild = next; 76680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 76780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return curr; 76880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 76980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 77080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////// 77180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////// 77280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 77380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 77480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 77558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenbergervoid SkView::validate() const { 77658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger// SkASSERT(this->getRefCnt() > 0 && this->getRefCnt() < 100); 77758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger if (fParent) { 77858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger SkASSERT(fNextSibling); 77958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger SkASSERT(fPrevSibling); 78058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } else { 78158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger bool nextNull = NULL == fNextSibling; 78258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger bool prevNull = NULL == fNextSibling; 78358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger SkASSERT(nextNull == prevNull); 78458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger } 78558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger} 78658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger 78780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic inline void show_if_nonzero(const char name[], SkScalar value) 78880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 78980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (value) 79080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("%s=\"%g\"", name, value/65536.); 79180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 79280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 79380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void tab(int level) 79480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 79580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int i = 0; i < level; i++) 79680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf(" "); 79780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 79880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 79980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void dumpview(const SkView* view, int level, bool recurse) 80080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 80180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tab(level); 80280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 80380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("<view"); 80480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru show_if_nonzero(" x", view->locX()); 80580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru show_if_nonzero(" y", view->locY()); 80680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru show_if_nonzero(" width", view->width()); 80780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru show_if_nonzero(" height", view->height()); 80880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 80980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (recurse) 81080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 81180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView::B2FIter iter(view); 81280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* child; 81380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool noChildren = true; 81480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 81580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while ((child = iter.next()) != NULL) 81680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 81780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (noChildren) 81880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf(">\n"); 81980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru noChildren = false; 82080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpview(child, level + 1, true); 82180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 82280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 82380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!noChildren) 82480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 82580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tab(level); 82680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("</view>\n"); 82780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 82880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 82980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto ONELINER; 83080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 83180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 83280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 83380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ONELINER: 83480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf(" />\n"); 83580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 83680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 83780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 83880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkView::dump(bool recurse) const 83980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 84080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpview(this, 0, recurse); 84180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 84280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 84380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 844