Ejemplo n.º 1
0
void WebListBox::ResizeScrollBars(void)
{
	if (mpHScroll)
	{
		WebRect r;
		r.Set(GetMargin() + GetBorder(),
		      Height() - GetMargin() - GetBorder() - miSliderWidth - 1,
		      Width() - (mpVScroll ? miSliderWidth : 0) - GetMargin() - GetBorder() - 1,
		      Height() - GetMargin() - GetBorder() - 1);
		mpHScroll->Move(&r);
		WebRect vr;
		GetOptionsRect(&vr);
		mpHScroll->SetWindow(vr.Width());
		mpHScroll->Invalidate();
	}
	if (mpVScroll)
	{
		WebRect r;
		r.Set(Width() - 1 - GetMargin() - GetBorder() - miSliderWidth,
		      GetMargin() + GetBorder(),
		      Width() - 1 - GetMargin() - GetBorder(),
		      Height() - 1 - (mpHScroll ? miSliderWidth : 0) - GetMargin() - GetBorder());
		mpVScroll->Move(&r);
		WebRect vr;
		GetOptionsRect(&vr);
		mpVScroll->SetWindow(vr.Height());
		mpVScroll->Invalidate();

	}
}
Ejemplo n.º 2
0
void WebListBox::FitSelection(void)
{
	if (UseVScroll())
	{
		DISPLAY_INT offsetX, offsetY;
		WebRect r;

		GetScrollOffset(&offsetX, &offsetY);
		GetOptionsRect(&r);

		int pos = miSelected * (miTextHeight + GetSpacing());
		if (pos < offsetY)
		{
			mpVScroll->SetPosition(pos);
		}
		else if (pos > offsetY + r.Height() - miTextHeight - GetSpacing())
		{
			mpVScroll->SetPosition(pos - r.Height() + miTextHeight + GetSpacing());
		}
	}
}
Ejemplo n.º 3
0
void DisplayManager::CorrectViewportPosition (void)
{
	if (mRoot.Get())
	{
		WebRect bounds;
		PresetWebRect rect(&mViewRect);

		GetRootBounds(&bounds);
		rect.MoveTo(0,0);
		bounds.Or(&rect);

		if (mViewRect.left < bounds.left)
		{
			mViewRect.Shift(bounds.left - mViewRect.left, 0);
		}

		if (mViewRect.right > bounds.right)
		{
			mViewRect.Shift(bounds.right - mViewRect.right, 0);
		}

		if (mViewRect.top < bounds.top)
		{
			mViewRect.Shift(0, bounds.top - mViewRect.top);
		}

		if (mViewRect.bottom > bounds.bottom)
		{
			mViewRect.Shift(0, bounds.bottom - mViewRect.bottom);
		}

		if (mpVScroll)
		{
			// Range and Window must be set BEFORE Position,
			//  so position is not unjustly clipped!
			mpVScroll->SetRange(bounds.Height());
			mpVScroll->SetWindow(mViewRect.Height());
			mpVScroll->SetPosition(mViewRect.top);
		}

		if (mpHScroll)
		{
			// Range and Window must be set BEFORE Position,
			//  so position is not unjustly clipped!
			mpHScroll->SetRange(bounds.Width());
			mpHScroll->SetWindow(mViewRect.Width());
			mpHScroll->SetPosition(mViewRect.left);
		}
	}
}
Ejemplo n.º 4
0
FormatResult HTMLBodyDisplay::FormatForViewport (
		WebRect* viewportRect,
		WEBC_BOOL hscrollPresent,
		WEBC_BOOL vscrollPresent
	)
{
	if (Width() != viewportRect->Width())
	{
		SizeTo(viewportRect->Width(), viewportRect->Height());
		SetParentStyleModified();
	}
	else if (Height() != viewportRect->Height())
	{
		SizeTo(viewportRect->Width(), viewportRect->Height());
		SetPosChildStyleModified();
	}

	FormatIfNecessary();
	CSSPropertyValue overflowValue;
	if (mpHtmlElement->GetStyleFromCSS(CSS_PROPERTY_OVERFLOW, &overflowValue) == CSS_VALUE_SPECIFIED)
	{
		if (CSS_OVERFLOW_HIDDEN == overflowValue.overflow)
		{
			return (DISPLAY_FORMAT_SUCCESS);
		}
	}
#if (WEBC_SUPPORT_SCROLLBARS)
	WebRect bounds;
	GetBounds(&bounds);

	if (bounds.Height() > viewportRect->Height() && !vscrollPresent)
	{
		return (DISPLAY_FORMAT_NEEDS_VSCROLL);
	}

	if (bounds.Width() > viewportRect->Width() && !hscrollPresent)
	{
		return (DISPLAY_FORMAT_NEEDS_HSCROLL);
	}
#endif
	return (DISPLAY_FORMAT_SUCCESS);
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
template<class T> IPositionedFormatContext* HTMLElementDisplay<T>::FormatSelfPositioned (
		DisplayElement* displayParent,
		IPositionedFormatContext* rootContext,
		IPositionedFormatContext* parentContext,
		FormatContextFactory* childContextFactory,
		WEBC_BOOL generateChildContext
	)
{
	WebRect rect;
	WEBC_UINT16 position = GetPosition();
	IPositionedFormatContext* childContext = 0;

	if (position == TU_POSITION_RELATIVE)
	{
		if (generateChildContext)
		{
			const WebRect * tmpRect = 	&(((DisplayElement *)(this))->mRect);
			rect.Set(tmpRect);
			rect.MoveTo(0,0);

			CSSLength height;
			GetCSSLength(&height, CSS_PROPERTY_HEIGHT);

			childContext = childContextFactory->newPositioned (
					&rect,
					(height.type == CSS_LENGTH_UNIT_AUTO) ||
					(height.type == CSS_LENGTH_UNIT_PERCENT && parentContext->parentHeightIsAuto()), // parent height is auto
					TU_DIR_LTR,
					0, // border-left-width
					0, // border-top-width
					0, // border-right-width
					0, // border-bottom-width
					0, // autoIndentLeft
					0, // autoIndentTop
					0  // autoIndentRight
				);
		}
	}
	else
	{
		WebRect containingBlock;
		IPositionedFormatContext* containingContext;
		DISPLAY_INT borderLeftValue;
		DISPLAY_INT borderTopValue;
		DISPLAY_INT borderRightValue;
		DISPLAY_INT borderBottomValue;

		if (displayParent)
		{
			if (displayParent != T::mpParent)
			{
				mHtmlElementDisplayFlags &= ~HELEM_DISPLAY_FLAG_STYLE_SET;
			}
			displayParent->InsertOrdered(this);
		}

		if (position == TU_POSITION_FIXED)
		{
			T::SetFixedPosition(WEBC_TRUE);
			containingContext = rootContext;
		}
		else
		{
			T::SetFixedPosition(WEBC_FALSE);
			containingContext = parentContext;
		}

		containingContext->getContainingBlock(&containingBlock);

		WEBC_BOOL   parentHeightIsAuto = containingContext->parentHeightIsAuto();
		int         textDirection      = containingContext->getTextDirection();
		DISPLAY_INT parentBorderLeft   = containingContext->getParentBorderLeft();
		DISPLAY_INT parentBorderTop    = containingContext->getParentBorderTop();
		DISPLAY_INT parentBorderRight  = containingContext->getParentBorderRight();
		DISPLAY_INT parentBorderBottom = containingContext->getParentBorderBottom();

		DISPLAY_INT autoIndentLeft     = parentContext->getAutoIndentLeft();
		DISPLAY_INT autoIndentTop      = parentContext->getAutoIndentTop();
		DISPLAY_INT autoIndentRight    = parentContext->getAutoIndentRight();

		if (position == TU_POSITION_FIXED)
		{
			WebRect parentRect;

			parentContext->getContainingBlock(&parentRect);

			autoIndentLeft  += parentRect.left;
			autoIndentTop   += parentRect.top;
			autoIndentRight += (containingBlock.right - parentRect.right);
		}

		DISPLAY_INT parentWidth = containingBlock.Width() - (parentBorderLeft + parentBorderRight);
		DISPLAY_INT parentHeight = containingBlock.Height() - (parentBorderTop + parentBorderBottom);

		WebFont font = mpHtmlElement->GetWebFont();
		DISPLAY_INT emHeight = font? WEB_FONT_HEIGHT(font) : WEBC_CFG_DEFAULT_TEXT_HEIGHT;
		DISPLAY_INT exHeight = emHeight >> 1;

		// First find the left edge and width

		CSSLength left;
		CSSLength right;
		CSSLength width;

		// Find value for left, right, width, marginLeft, marginRight

		GetCSSLength(&left,  CSS_PROPERTY_LEFT);
		GetCSSLength(&right, CSS_PROPERTY_RIGHT);
		GetCSSLength(&width, CSS_PROPERTY_WIDTH);

		DISPLAY_INT leftValue;
		DISPLAY_INT rightValue;
		DISPLAY_INT widthValue;
		DISPLAY_INT marginLeftValue;
		DISPLAY_INT paddingLeftValue;
		DISPLAY_INT paddingTopValue;
		DISPLAY_INT paddingRightValue;
		DISPLAY_INT paddingBottomValue;

		// Find value for padding and border

		paddingLeftValue   = GetPixelLength(CSS_PROPERTY_PADDING_LEFT,   parentWidth, emHeight, exHeight, 0);
		paddingTopValue    = GetPixelLength(CSS_PROPERTY_PADDING_TOP,    parentWidth, emHeight, exHeight, 0);
		paddingRightValue  = GetPixelLength(CSS_PROPERTY_PADDING_RIGHT,  parentWidth, emHeight, exHeight, 0);
		paddingBottomValue = GetPixelLength(CSS_PROPERTY_PADDING_BOTTOM, parentWidth, emHeight, exHeight, 0);

		borderLeftValue    = GetBorderWidth(CSS_LEFT,   parentWidth, emHeight, exHeight, parentBorderLeft);
		borderTopValue     = GetBorderWidth(CSS_TOP,    parentWidth, emHeight, exHeight, parentBorderTop);
		borderRightValue   = GetBorderWidth(CSS_RIGHT,  parentWidth, emHeight, exHeight, parentBorderRight);
		borderBottomValue  = GetBorderWidth(CSS_BOTTOM, parentWidth, emHeight, exHeight, parentBorderBottom);

		CSSLength height;
		CSSLength top;
		CSSLength bottom;
		DISPLAY_INT heightValue=0;
		WEBC_BOOL heightIsAuto=0;

		GetCSSLength(&height, CSS_PROPERTY_HEIGHT);
		GetCSSLength(&top, CSS_PROPERTY_TOP);

#define NOTHING_KNOWN 0
#define HEIGHT_KNOWN  1
#define TOP_KNOWN     2
#define BOTTOM_KNOWN  4

		WEBC_UINT8 verticalCase;

		verticalCase =  (height.type == CSS_LENGTH_UNIT_AUTO ||
		                 (height.type == CSS_LENGTH_UNIT_PERCENT && parentHeightIsAuto))? 0 : HEIGHT_KNOWN;
		verticalCase |= (top.type == CSS_LENGTH_UNIT_AUTO)? 0 : TOP_KNOWN;

		if (verticalCase != (HEIGHT_KNOWN|TOP_KNOWN))
		{
			GetCSSLength(&bottom, CSS_PROPERTY_BOTTOM);
			verticalCase |= (bottom.type == CSS_LENGTH_UNIT_AUTO || parentHeightIsAuto)? 0 : BOTTOM_KNOWN;
		}

		DISPLAY_INT topValue = 0;
		DISPLAY_INT bottomValue = 0;
		DISPLAY_INT marginTopValue = 0;
		DISPLAY_INT marginBottomValue = 0;

		switch (verticalCase)
		{
			case NOTHING_KNOWN:
				// top = auto indent top
				// height = content height
				topValue = autoIndentTop;
				heightValue = 0;
				heightIsAuto = WEBC_TRUE;
				marginTopValue = GetPixelLength(CSS_PROPERTY_MARGIN_TOP, parentWidth, emHeight, exHeight, 0);
				break;

			case HEIGHT_KNOWN:
				// top = auto indent top
				// height = height
				topValue = autoIndentTop;
				heightValue = CSS_LengthToPixels(&height, parentHeight, emHeight, exHeight);
				heightIsAuto = WEBC_FALSE;
				marginTopValue = GetPixelLength(CSS_PROPERTY_MARGIN_TOP, parentWidth, emHeight, exHeight, 0);
				break;

			case TOP_KNOWN:
				// top = top
				// height = content height
				if (top.type == CSS_LENGTH_UNIT_PERCENT && parentHeightIsAuto)
				{
					topValue = autoIndentTop;
				}
				else
				{
					topValue = CSS_LengthToPixels(&top, parentHeight, emHeight, exHeight);
				}
				heightValue = 0;
				heightIsAuto = WEBC_TRUE;
				marginTopValue = GetPixelLength(CSS_PROPERTY_MARGIN_TOP, parentWidth, emHeight, exHeight, 0);
				break;

			case HEIGHT_KNOWN|TOP_KNOWN:
				// top = top
				// height = height
				if (top.type == CSS_LENGTH_UNIT_PERCENT && parentHeightIsAuto)
				{
					topValue = autoIndentTop;
				}
				else
				{
					topValue = CSS_LengthToPixels(&top, parentHeight, emHeight, exHeight);
				}
				heightValue = CSS_LengthToPixels(&height, parentHeight, emHeight, exHeight);
				heightIsAuto = WEBC_FALSE;
				marginTopValue = GetPixelLength(CSS_PROPERTY_MARGIN_TOP, parentWidth, emHeight, exHeight, 0);
				break;

			case BOTTOM_KNOWN:
				// bottom = bottom
				// height = content height
				// top = parentHeight - (height + bottom)
				bottomValue = GetPixelLength(&bottom, parentHeight, emHeight, exHeight, 0);
				marginBottomValue = GetPixelLength(CSS_PROPERTY_MARGIN_BOTTOM, parentWidth, emHeight, exHeight, 0);
				heightValue = 0;
				heightIsAuto = WEBC_TRUE;
				break;

			case HEIGHT_KNOWN|BOTTOM_KNOWN:
				// bottom = bottom
				// height = height
				// top = parentHeight - (height + bottom)
				bottomValue = GetPixelLength(&bottom, parentHeight, emHeight, exHeight, 0);
				heightValue = CSS_LengthToPixels(&height, parentHeight, emHeight, exHeight);
				heightIsAuto = WEBC_FALSE;

				marginBottomValue = GetPixelLength(CSS_PROPERTY_MARGIN_BOTTOM, parentWidth, emHeight, exHeight, 0);

				topValue = parentHeight -
			               (borderTopValue +
			                paddingTopValue +
			                heightValue +
			                paddingBottomValue +
			                borderBottomValue +
			                marginBottomValue +
			                bottomValue);
				break;

			case TOP_KNOWN|BOTTOM_KNOWN:
				// top = top
				// bottom = bottom
				// height = parentHeight - (top + bottom)
				if (top.type == CSS_LENGTH_UNIT_PERCENT && parentHeightIsAuto)
				{
					topValue = autoIndentTop;
				}
				else
				{
					topValue = CSS_LengthToPixels(&top, parentHeight, emHeight, exHeight);
				}
				bottomValue = GetPixelLength(&bottom, parentHeight, emHeight, exHeight, 0);

				marginTopValue = GetPixelLength(CSS_PROPERTY_MARGIN_TOP, parentWidth, emHeight, exHeight, 0);
				marginBottomValue = GetPixelLength(CSS_PROPERTY_MARGIN_BOTTOM, parentWidth, emHeight, exHeight, 0);

				heightValue = parentHeight -
				              (topValue +
							   marginTopValue +
							   borderTopValue +
							   paddingTopValue +
				               paddingBottomValue +
							   borderBottomValue +
							   marginBottomValue +
							   bottomValue);
				heightIsAuto = WEBC_FALSE;
				break;
		}

		if (width.type != CSS_LENGTH_UNIT_AUTO)
		{
			widthValue = CSS_LengthToPixels(&width, parentWidth, emHeight, exHeight);

			WEBC_BOOL leftAligned = (textDirection == TU_DIR_RTL)?
			                            (right.type == CSS_LENGTH_UNIT_AUTO && left.type  != CSS_LENGTH_UNIT_AUTO) :
										(left.type  != CSS_LENGTH_UNIT_AUTO || right.type == CSS_LENGTH_UNIT_AUTO);

			if (leftAligned)
			{
				// ignore right and margin-right
				leftValue = GetPixelLength(&left, parentWidth, emHeight, exHeight, autoIndentLeft);
				marginLeftValue = GetPixelLength(CSS_PROPERTY_MARGIN_LEFT, parentWidth, emHeight, exHeight, 0);
			}
			else
			{
				DISPLAY_INT marginRightValue;

				// ignore left and margin-left
				rightValue = GetPixelLength(&right, parentWidth, emHeight, exHeight, autoIndentRight);
				marginRightValue = GetPixelLength(CSS_PROPERTY_MARGIN_RIGHT, parentWidth, emHeight, exHeight, 0);
				leftValue = parentWidth -
				            (rightValue +
							 marginRightValue +
							 borderRightValue +
							 paddingRightValue +
				             widthValue +
							 paddingLeftValue +
							 borderLeftValue);

				marginLeftValue = 0;
			}
		}
		else
		{
			// width.type == CSS_LENGTH_UNIT_AUTO

			// try to get the intrinsic width of the element.  This might rely on the
			//  calculated height of the element; for example, in the case of an image with
			//  specified height and auto width, the aspect ratio of the source image determines
			//  the resulting intrinsic width.

			DISPLAY_INT marginRightValue;
			WEBC_BOOL hasIntrinsicWidth = GetIntrinsicWidth(&widthValue, heightValue, heightIsAuto);

			if (left.type == CSS_LENGTH_UNIT_AUTO && right.type != CSS_LENGTH_UNIT_AUTO && hasIntrinsicWidth)
			{
				rightValue = GetPixelLength(&right, parentWidth, emHeight, exHeight, autoIndentRight);
				marginRightValue = GetPixelLength(CSS_PROPERTY_MARGIN_RIGHT, parentWidth, emHeight, exHeight, 0);
				marginLeftValue = 0;

				leftValue = parentWidth -
							 (widthValue +
							  borderLeftValue +
							  paddingLeftValue +
							  paddingRightValue +
							  borderRightValue +
							  marginRightValue +
							  rightValue);
			}
			else
			{
				leftValue = GetPixelLength(&left,  parentWidth, emHeight, exHeight, autoIndentLeft);
				marginLeftValue = GetPixelLength(CSS_PROPERTY_MARGIN_LEFT,  parentWidth, emHeight, exHeight, 0);

				if (!hasIntrinsicWidth || (right.type != CSS_LENGTH_UNIT_AUTO && left.type != CSS_LENGTH_UNIT_AUTO))
				{
					// right and left are both non-auto, OR element has no intrinsic width:
					//  calculate left, right, and margins then extrapolate width
					rightValue = GetPixelLength(&right, parentWidth, emHeight, exHeight, autoIndentRight);
					marginRightValue = GetPixelLength(CSS_PROPERTY_MARGIN_RIGHT, parentWidth, emHeight, exHeight, 0);

					widthValue = parentWidth -
								 (leftValue +
								  marginLeftValue +
								  borderLeftValue +
								  paddingLeftValue +
								  paddingRightValue +
								  borderRightValue +
								  marginRightValue +
								  rightValue);

					// we don't want to stretch the width beyond what the maximum content
					//  width; only give the element as much space as it actually needs.
					if (right.type == CSS_LENGTH_UNIT_AUTO || left.type == CSS_LENGTH_UNIT_AUTO)
					{
						// to speed this up, bail out of GetMaxWidth when we exceed widthValue
						DISPLAY_INT maxWidth = GetMaxWidthSmallerThan(widthValue);

						// NOTE: GetMaxWidth and GetMaxWidthSmallerThan return the total width
						//  of the element, including borders and padding.  So we must subtract
						//  borders and padding to make it correspond to the contentWidth

						maxWidth -= (borderLeftValue + paddingLeftValue + paddingRightValue + borderRightValue);

						if (maxWidth < widthValue)
						{
							WEBC_BOOL leftAligned = (textDirection == TU_DIR_RTL)?
														(right.type == CSS_LENGTH_UNIT_AUTO && left.type  != CSS_LENGTH_UNIT_AUTO) :
														(left.type  != CSS_LENGTH_UNIT_AUTO || right.type == CSS_LENGTH_UNIT_AUTO);

							if (!leftAligned)
							{
								// box is right-aligned
								//  adjust leftValue to account for the unused space
								leftValue += (widthValue - maxWidth);
							}
							widthValue = maxWidth;
						}
					}
				}
			}
		}

		// Now format the content of this element

		DISPLAY_INT contentHeight = FormatContentPositioned (
				widthValue,
				heightValue,
				heightIsAuto,
				borderLeftValue,
				borderTopValue,
				borderRightValue,
				borderBottomValue,
				paddingLeftValue,
				paddingTopValue,
				paddingRightValue,
				paddingBottomValue
			);

		// Find the top edge and height

		//  NOTE: top and bottom percentages are relative to parent's HEIGHT, whereas
		//   margin-top and margin-bottom are relative to parent's WIDTH, except in the root
		//   context (tbd - handle this special case correctly)

		switch (verticalCase)
		{
			case NOTHING_KNOWN:
			case TOP_KNOWN:
				heightValue = contentHeight;
				break;

			case BOTTOM_KNOWN:
				// height = content height
				// top = parentHeight - (height + bottom)
				heightValue = contentHeight;
				topValue = parentHeight -
			               (borderTopValue +
			                paddingTopValue +
			                heightValue +
			                paddingBottomValue +
			                borderBottomValue +
			                marginBottomValue +
			                bottomValue);
				break;
		}

		rect.Set (0, 0,
				borderLeftValue + paddingLeftValue + widthValue  + paddingRightValue  + borderRightValue - 1,
				borderTopValue  + paddingTopValue  + heightValue + paddingBottomValue + borderBottomValue - 1
			);

		rect.MoveTo (
				parentBorderLeft + leftValue + marginLeftValue,
				parentBorderTop + topValue  + marginTopValue
			);

		if (position == TU_POSITION_FIXED)
		{
			rect.Shift(containingBlock.left, containingBlock.top);
		}

		Move(&rect);

		if (generateChildContext)
		{
			childContext = childContextFactory->newPositioned (
					&rect,
					heightIsAuto,
					TU_DIR_LTR,
					borderLeftValue,
					borderTopValue,
					borderRightValue,
					borderBottomValue,
					paddingLeftValue,
					paddingTopValue,
					paddingRightValue
				);
		}
	}

	return (childContext);
}
Ejemplo n.º 6
0
void DisplayManager::UpdateScrollBuffer (void)
{
	if ((GetManagerFlags() & MANAGER_FLAG_DIRTY) &&
	    mRoot.Get() &&
		mScrollBuffer)
	{
		WebRect* dirty;

		ClearManagerFlag(MANAGER_FLAG_BUFFER_DIRTY);

		// move the dirty rectangle list onto the stack so it can't be corrupted
		vector dirtyListCopy = mDirtyList;

		mDirtyList.first = 0;
		mDirtyList.last = 0;

		vector_iterator vi;

		DISPLAY_INT viewWidth  = mViewRect.Width();
		DISPLAY_INT viewHeight = mViewRect.Height();

		PresetWebRect viewCorner(&mViewRect);
		viewCorner.MoveTo(0,0);

		PresetWebRect bufferView(&mViewRect);
		bufferView.MoveTo(mViewRect.left % viewWidth, mViewRect.top % viewHeight);

		DISPLAY_INT bufferLeft = mViewRect.left - (mViewRect.left % viewWidth);
		DISPLAY_INT bufferTop  = mViewRect.top  - (mViewRect.top  % viewHeight);

		dirty = (WebRect*) vector_get_first(&dirtyListCopy, &vi);
		while (dirty)
		{
			if (mViewRect.Overlaps(dirty))
			{
				WebRect bufferDirty;
				bufferDirty.left = dirty->left - bufferLeft;
				bufferDirty.top  = dirty->top  - bufferTop;
				bufferDirty.SizeTo(dirty->Width(), dirty->Height());
				bufferDirty.And(&bufferView);

				mScrollBuffer->SetClip(&bufferDirty);

				DISPLAY_INT x = mRoot.Get()->mRect.left - bufferLeft;
				DISPLAY_INT y = mRoot.Get()->mRect.top  - bufferTop;

				mRoot.Get()->Draw (x, y, &bufferView, mScrollBuffer);

				PresetWebRect defaultClip(0, 0, viewWidth * 2 - 1, viewHeight * 2 - 1);
				mScrollBuffer->SetClip(&defaultClip);

				// copy bufferDirty 3 times, split if necessary
				PresetWebRect northwest (0, 0, viewWidth - 1, viewHeight - 1);
				PresetWebRect northeast (viewWidth, 0, viewWidth * 2 - 1, viewHeight - 1);
				PresetWebRect southeast (viewWidth, viewHeight, viewWidth * 2 - 1, viewHeight * 2 - 1);
				PresetWebRect southwest (0, viewHeight, viewWidth - 1, viewHeight * 2 - 1);

				if (bufferDirty.Overlaps(&northwest))
				{
					PresetWebRect copyFrom (&bufferDirty);
					copyFrom.And(&northwest);

					PresetWebRect copyTo (&copyFrom);

					copyTo.ShiftOver(mViewRect.Width());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftDown(mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftOver(-mViewRect.Width());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);
				}

				if (bufferDirty.Overlaps(&northeast))
				{
					PresetWebRect copyFrom (&bufferDirty);
					copyFrom.And(&northeast);

					PresetWebRect copyTo (&copyFrom);

					copyTo.ShiftDown(mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftOver(-mViewRect.Width());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftDown(-mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);
				}

				if (bufferDirty.Overlaps(&southeast))
				{
					PresetWebRect copyFrom (&bufferDirty);
					copyFrom.And(&southeast);

					PresetWebRect copyTo (&copyFrom);

					copyTo.ShiftDown(-mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftOver(-mViewRect.Width());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftDown(mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);
				}

				if (bufferDirty.Overlaps(&southwest))
				{
					PresetWebRect copyFrom (&bufferDirty);
					copyFrom.And(&southwest);

					PresetWebRect copyTo (&copyFrom);

					copyTo.ShiftDown(-mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftOver(mViewRect.Width());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);

					copyTo.ShiftDown(mViewRect.Height());
					mScrollBuffer->CopyBufferRegion(&copyTo, mScrollBuffer, copyFrom.left, copyFrom.top);
				}
			}

			dirty = (WebRect*) vector_get_next(&vi);
		}

		// this ensures the dirty list is just the same as when we entered
		vector_delete(&mDirtyList);

		if (!this->GetManager())
		{
			// if we're the root manager, we'll need this list in a sec.
			mDirtyList = dirtyListCopy;
		}
		else
		{
			ClearManagerFlag(MANAGER_FLAG_DIRTY);
			vector_delete(&dirtyListCopy);
		}
	}
}
Ejemplo n.º 7
0
void DisplayManager::Draw(DISPLAY_INT x, DISPLAY_INT y, WebRect *pViewport, WebGraphics *pGC)
{
	if (mNoRefresh)
	{
		DisplayManager* parentDisplayManager = GetManager();

		if (parentDisplayManager)
		{
			// This handles the case where a DisplayManager that is NOT the root
			//  DisplayManager has a positive refresh lock, prohibiting its being
			//  drawn, but the parent DisplayManager does not (otherwise we would
			//  not even be in our Draw method); in this case:
			//
			// IF this element is within the collective invalid region being
			//    painted, THEN we want to re-invalidate the invalid part of (this),
			//    which will cause said region to re-paint when the refresh lock
			//    is removed from this element and this->Refresh is eventually called.

			WebRect clipRect;
			pGC->GetClip(&clipRect);

			WebRect screenRect(mRect);
			screenRect.MoveTo(x,y);

			if (clipRect.Overlaps(&screenRect))
			{
				SetManagerFlag(MANAGER_FLAG_TRIED_TO_DRAW);
				//screenRect.And(&clipRect);
				//screenRect.Shift(-pViewport->left, -pViewport->top);
				//parentDisplayManager->InvalidateViewportRegion(&screenRect);
			}
		}

		return;
	}

	FormatResult result;

	switch (GetScrollMode())
	{
		case SCROLL_MODE_NONE:
			if (mpVScroll || mpHScroll)
			{
				DetachVScroll();
				DetachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_HSCROLL:
			if (mpVScroll || !mpHScroll)
			{
				DetachVScroll();
				AttachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_VSCROLL:
			if (!mpVScroll || mpHScroll)
			{
				AttachVScroll();
				DetachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_BOTH:
			if (!mpVScroll || !mpHScroll)
			{
				AttachVScroll();
				AttachHScroll();
				UpdateViewport();
			}
			break;

		case SCROLL_MODE_AUTO:
			break;
	}

	if (mRoot.Get())
	{
		int i = 0;

		do
		{
			result = mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));

			if (GetScrollMode() == SCROLL_MODE_AUTO)
			{
				if (result == DISPLAY_FORMAT_NEEDS_VSCROLL)
				{
					// create a vscroll bar
					if (mpVScroll)
					{
						// what the... we already have a vscroll bar!
						break;
					}
					AttachVScroll();

					// check for creation failure - may indicate low memory condition
					if (!mpVScroll)
					{
						// can't go on...
						break;
					}

					UpdateViewport();
				}
				else if (result == DISPLAY_FORMAT_NEEDS_HSCROLL)
				{
					// create a hscroll bar
					if (mpHScroll)
					{
						// what the... we already have a hscroll bar!
						break;
					}
					AttachHScroll();

					// check for creation failure - may indicate low memory condition
					if (!mpHScroll)
					{
						// can't go on...
						break;
					}

					UpdateViewport();
				}
			}
			else
			{
				break;
			}

			// put a hard upper bound on the number of times we try to re-format
			//  (4, since this means we've covered all combinations of horizontal
			//   and vertical scroll bars on the window)
			i++;
		}
		while (result != DISPLAY_FORMAT_SUCCESS && i < 5);

		if (GetScrollMode() == SCROLL_MODE_AUTO)
		{
			WebRect rootBounds;
			GetRootBounds(&rootBounds);

			if (rootBounds.Height() <= mViewRect.Height() && mpVScroll)
			{
				DetachVScroll();
				UpdateViewport();
				mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));
				GetRootBounds(&rootBounds);
			}

			if (rootBounds.Width() <= mViewRect.Width() && mpHScroll)
			{
				DetachHScroll();
				UpdateViewport();
				mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));
				GetRootBounds(&rootBounds);
			}

			if (rootBounds.Height() <= mViewRect.Height() && mpVScroll)
			{
				DetachVScroll();
				UpdateViewport();
				mRoot.Get()->FormatForViewport(&mViewRect, (mpHScroll != 0), (mpVScroll != 0));
				GetRootBounds(&rootBounds);
			}
		}

		mViewportChanged = WEBC_FALSE;

		CorrectViewportPosition();

		if (mpFocus && (mpVScroll!=0) && (mpHScroll!=0))
		{
			WebRect focusRect;
			WebRect elemRect;
			WEBC_BOOL ensureFocusVisible = mpFocus->GetFocusRect (&focusRect);
			if (ensureFocusVisible)
			{
				GetElementRect(&elemRect, mpFocus);
				focusRect.Shift(elemRect.left, elemRect.top);

				// this will adjust the scroll bars so that the given rect is in view
				EnsureRectVisible(&focusRect);
			}
		}
	}

	DisplayElement::Draw(x, y, pViewport, pGC);
}
Ejemplo n.º 8
0
void DisplayElement::Draw (DISPLAY_INT iScreenX, DISPLAY_INT iScreenY, WebRect *pViewport, WebGraphics *pGC)
{
	DisplayElement *pChild = mpFirstChild;
	WebRect clip, saveClip, screenClip;
	WEBC_BOOL clipRestore = WEBC_FALSE;

	pGC->GetClip(&saveClip);
	clip.Set(&saveClip);
	if (GetOverflow() != DISPLAY_OVERFLOW_VISIBLE)
	//if (GetOverflow() == DISPLAY_OVERFLOW_HIDDEN)
	{
		GetClipRect(&screenClip);
		screenClip.Shift(iScreenX - mRect.left, iScreenY - mRect.top);
		if (!clip.Overlaps(&screenClip))
		{
			// we're not visible, so neither are our children
			return;
		}
		clip.And(&screenClip);
		pGC->SetClip(&clip);
		clipRestore = WEBC_TRUE;
	}

	WebRect screenRect(mRect);
	screenRect.MoveTo(iScreenX, iScreenY);
	mScreenRect = screenRect; // April2013 - save the screenrect of last known draw and subtract boundaries of the display manager screenrect
	DisplayManager*pManager= this->GetManager();
	if (pManager && pManager->mBrowser)
		pManager=pManager->mBrowser->GetDisplayManager();
	if (pManager)
	{
	WebRect r;
//	printf("Not working all the way \n");
		r=pManager->mScreenRect;
		mScreenRect.top -= r.top;
		mScreenRect.bottom -= r.top;
		mScreenRect.left -= r.left;
		mScreenRect.right -= r.left;
	}  // April2013 - end save the screenrect of last known draw and subtract boundaries of the display manager screenrect
	// Start drawing
//	pGC->StartBuffer();

	// Draw negative-z children
	while (pChild && (pChild->GetZIndex() < 0))
	{
		if (pChild->mFlags & DISPLAY_FLAG_FIXED_POS)
		{
			pChild->Draw(pViewport->left + pChild->mRect.left, pViewport->top + pChild->mRect.top, pViewport, pGC);
		}
		else
		{
			pChild->Draw(iScreenX + pChild->mRect.left, iScreenY + pChild->mRect.top, pViewport, pGC);
		}
		pChild = pChild->mpNext;
	}

	// if I am visible
	if (screenRect.Overlaps(&clip))
	{
		// Draw myself
		DrawThisOnly(iScreenX, iScreenY, pGC);
	}
#if (INCLUDE_EXPERIMENTAL_DIV_SCROLLBARS)
	int xContentOffset=0;
	int yContentOffset=0;

	if (clipRestore && vScrollWidth() || hScrollWidth())
	{
		WebRect contentClip;
		contentClip.Set(&clip);
		contentClip.SetHeight(contentClip.Height()-hScrollWidth());
		contentClip.SetWidth(contentClip.Width()-vScrollWidth());
		pGC->SetClip(&contentClip);

		if (GetHScroll())
		{
			WebHScroll *pScroll = (WebHScroll *)GetHScroll();
			xContentOffset=pScroll->GetPosition();
		}
		if (GetVScroll())
		{
			WebVScroll *pScroll = (WebVScroll *)GetVScroll();
			yContentOffset=pScroll->GetPosition();
			if (yContentOffset)
			{ // If we have a y offset step i nto the content holder element
			  // so we don't exclude the whole thing becuase it is out of our
			  // range.
		//		if (GetInlineContentHolder())
		//			pChild = GetInlineContentHolder()->mpFirstChild;
				;
			}
		}
	}
#endif

	// Draw positive-z children
	while (pChild)
	{
#if (INCLUDE_EXPERIMENTAL_DIV_SCROLLBARS)
		if (pChild->IncludeInFlow() && pChild->mRect.bottom >= yContentOffset && pChild->mRect.right >= xContentOffset)
		{
			if (pChild->mFlags & DISPLAY_FLAG_FIXED_POS)
			{
				pChild->Draw(pViewport->left+pChild->mRect.left-xContentOffset, pViewport->top+pChild->mRect.top-yContentOffset, pViewport, pGC);
			}
			else
			{
				pChild->Draw(iScreenX + pChild->mRect.left-xContentOffset, iScreenY+pChild->mRect.top-yContentOffset, pViewport, pGC);
			}
		}
#else
		if (pChild->mFlags & DISPLAY_FLAG_FIXED_POS)
		{
			pChild->Draw(pViewport->left + pChild->mRect.left, pViewport->top + pChild->mRect.top, pViewport, pGC);
		}
		else
		{
			pChild->Draw(iScreenX + pChild->mRect.left, iScreenY + pChild->mRect.top, pViewport, pGC);
		}
#endif
		pChild = pChild->mpNext;
	}


	if (clipRestore)
	{
		pGC->SetClip(&saveClip);
	}
#if (INCLUDE_EXPERIMENTAL_DIV_SCROLLBARS)
	if (clipRestore && vScrollWidth() || hScrollWidth())
	{
		DisplayElement *pScroll;
		if (GetHScroll())
		{
			pScroll = (WebHScroll *)GetHScroll();
			pScroll->Draw(iScreenX + pScroll->mRect.left, iScreenY + pScroll->mRect.top, pViewport, pGC);
		}
		if (GetVScroll())
		{
			pScroll = (WebVScroll *)GetVScroll();
			pScroll->Draw(iScreenX + pScroll->mRect.left, iScreenY + pScroll->mRect.top, pViewport, pGC);
		}
		pGC->SetClip(&saveClip);
	}
#endif
//	pGC->EndBuffer();
}
Ejemplo n.º 9
0
void WebListBox::SetupScrollBars(WebGraphics * gc)
{
	WebRect window;
	GetContentRect(&window);
	DISPLAY_INT w = window.Width();
	DISPLAY_INT h = window.Height();

	WEBC_BOOL needH, needV;
	needH = needV = WEBC_FALSE;

	for (int t = 0; t < 2; t++)
	{
		if (w < GetTotalTextWidth())
		{
			needH = WEBC_TRUE;
			h -= miSliderWidth;
		}
		if (h < GetTotalTextHeight())
		{
			needV = WEBC_TRUE;
			w -= miSliderWidth;
		}
	}

	if (needH && !mpHScroll)
	{
		WEBC_NEW_VERBOSE(mpHScroll, WebHScroll,"wtlist:WebVscroll");
		if (mpHScroll)
		{
			mpHScroll->SetListener(this);
			mpHScroll->SetRange(GetTotalTextWidth());
			mpHScroll->SetStep(miTextHeight);
			mpHScroll->SetPosition(0);
			if (mFlags & DISPLAY_FLAG_DISABLED)
			{
				mpHScroll->Disable();
			}
			InsertLast(mpHScroll);
			ResizeScrollBars();
		}
	}
	else if (!needH && mpHScroll)
	{
		Remove(mpHScroll);
		WEBC_DELETE(mpHScroll);
		mpHScroll = WEBC_NULL;
	}

	if (needV && !mpVScroll)
	{
		WEBC_NEW_VERBOSE(mpVScroll, WebVScroll,"Wtlist:WebVscroll");
		if (mpVScroll)
		{
			mpVScroll->SetListener(this);
			mpVScroll->SetRange(GetTotalTextHeight());
			mpVScroll->SetStep(miTextHeight + GetSpacing());
			mpVScroll->SetPosition(0);
			if (mFlags & DISPLAY_FLAG_DISABLED)
			{
				mpVScroll->Disable();
			}
			InsertLast(mpVScroll);
			ResizeScrollBars();
		}
	}
	else if (!needV && mpVScroll)
	{
		Remove(mpVScroll);
		WEBC_DELETE(mpVScroll);
		mpVScroll = WEBC_NULL;
	}

}
Ejemplo n.º 10
0
void WebDropBox::DrawThisOnly (DISPLAY_INT x, DISPLAY_INT y, WebGraphics *gc)
{
	WEBC_BOOL focused = (mFlags & DISPLAY_FLAG_FOCUS) || (mState == DROPBOX_STATE_DROPPED);

	mListbox.CalculateTextMetrics(gc);

	WebRect oldClip;
	gc->GetClip(&oldClip);
	WebRect clip;
	clip.top = y;
	clip.left = x;
	clip.bottom = y + Height() - 1;
	clip.right = x + Width() - 1;
	clip.And(&oldClip);

	gc->SetClip(&clip);

	WebRect rect;
	rect.top = y;
	rect.left = x;
	rect.bottom = y + Height() - 1;
	rect.right = x + Width() - 1;

//	gc->StartBuffer();

	WebColor hilite, lolite, blue, white, black;
	HTMLColor col = HTML_RGBAToColor(0,0,0,0);
	black = hilite = gc->RGBToColor(col);

	col = HTML_RGBAToColor(0xff,0xff,0xff,0);
	white = lolite = gc->RGBToColor(col);

	col = HTML_RGBAToColor(0,0,0xff,0);
	blue = gc->RGBToColor(col);

	if (focused)
	{
		gc->Rectangle(&rect, black, black, WEBC_FALSE);
	}

	GetFrameRect(&rect);
	rect.Shift(x,y);
	DrawFrame(&rect, gc);

	GetContentRect(&rect);
	rect.Shift(x,y);

	if (focused)
	{
		gc->Rectangle(&rect, GetSelectColor(gc), GetSelectColor(gc), WEBC_TRUE);
	}
	else
	{
		gc->Rectangle(&rect, GetBgColor(gc), GetBgColor(gc), WEBC_TRUE);
	}

	if (mpText && mFont.GetFont())
	{
		DISPLAY_INT offset = (rect.Height() - gc->TextHeight(mpText, mFont.GetFont())) / 2;

		clip.Set(&rect);
		clip.And(&oldClip);
		gc->SetClip(&clip);
		gc->Text(rect.left + DROPBOX_PADDING,
			 rect.top + DROPBOX_PADDING + offset,
			 mpText, (focused) ? GetBgColor(gc) : GetTextColor(gc),
			 0, WEBC_FALSE, mFont.GetFont());
	}

//	gc->EndBuffer();
	gc->SetClip(&oldClip);

}