/* static */ void
nsResizerFrame::ResizeContent(nsIContent* aContent, const Direction& aDirection,
                              const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo)
{
  // for XUL elements, just set the width and height attributes. For
  // other elements, set style.width and style.height
  if (aContent->IsXUL()) {
    if (aOriginalSizeInfo) {
      aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width,
                        aOriginalSizeInfo->width);
      aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height,
                        aOriginalSizeInfo->height);
    }
    // only set the property if the element could have changed in that direction
    if (aDirection.mHorizontal) {
      aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::width, aSizeInfo.width, true);
    }
    if (aDirection.mVertical) {
      aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::height, aSizeInfo.height, true);
    }
  }
  else {
    nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyleContent =
      do_QueryInterface(aContent);
    if (inlineStyleContent) {
      nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
      inlineStyleContent->GetStyle(getter_AddRefs(decl));

      if (aOriginalSizeInfo) {
        decl->GetPropertyValue(NS_LITERAL_STRING("width"),
                               aOriginalSizeInfo->width);
        decl->GetPropertyValue(NS_LITERAL_STRING("height"),
                               aOriginalSizeInfo->height);
      }

      // only set the property if the element could have changed in that direction
      if (aDirection.mHorizontal) {
        nsAutoString widthstr(aSizeInfo.width);
        if (!widthstr.IsEmpty() &&
            !Substring(widthstr, widthstr.Length() - 2, 2).EqualsLiteral("px"))
          widthstr.AppendLiteral("px");
        decl->SetProperty(NS_LITERAL_STRING("width"), widthstr, EmptyString());
      }
      if (aDirection.mVertical) {
        nsAutoString heightstr(aSizeInfo.height);
        if (!heightstr.IsEmpty() &&
            !Substring(heightstr, heightstr.Length() - 2, 2).EqualsLiteral("px"))
          heightstr.AppendLiteral("px");
        decl->SetProperty(NS_LITERAL_STRING("height"), heightstr, EmptyString());
      }
    }
  }
}
Beispiel #2
0
bool MCruxSpecParser::parseWindowElement(xmlNode *windowNode)
{
	wstring windowTitle;
	wstring url;
	unsigned int width = CW_USEDEFAULT;
	unsigned int height = CW_USEDEFAULT;

	//xmlChar * windowTitleName = xmlCharStrdup(MCRUXSPEC_WINDOW_TITLE_NAME);
	xmlChar * urlName = xmlCharStrdup(MCRUXSPEC_WINDOW_URL_NAME);

	map<wstring, wstring> attrlist;
	XMLParser::getProperties(windowNode->properties, attrlist);
	windowTitle = attrlist[L"title"];

	wstring wwidthstr = attrlist[L"width"];
	string widthstr(wwidthstr.begin(), wwidthstr.end());
	width = atoi(widthstr.c_str());

	wstring wheightstr = attrlist[L"height"];
	string heightstr(wheightstr.begin(), wheightstr.end());
	height = atoi(heightstr.c_str());

	for(xmlNode * child_prop = windowNode->children;
		child_prop;
		child_prop = child_prop->next)
	{
		if (0 == xmlStrcmp(child_prop->name, urlName))
		{
			url = getURL(child_prop);
		}
	}

	MCruxWindowConfiguration * winConf
		= new MCruxWindowConfiguration(windowTitle,
		width,
		height,
		url);
	windowConfigs.push_back(winConf);
	return true;
}