Commit f2c19221 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1790299 - Make XUL splitter use height property rather than attribute. r=jdescottes,tnikkel

Existing splitter and DevTools tests keep passing with this.

Differential Revision: https://phabricator.services.mozilla.com/D157062
parent d07f4468
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ loader.lazyRequireGetter(

/* A host should always allow this much space for the page to be displayed.
 * There is also a min-height on the browser, but we still don't want to set
 * frame.height to be larger than that, since it can cause problems with
 * frame.style.height to be larger than that, since it can cause problems with
 * resizing the toolbox and panel layout. */
const MIN_PAGE_SIZE = 25;

@@ -72,10 +72,11 @@ BottomHost.prototype = {
      ownerDocument,
      "devtools-toolbox-bottom-iframe"
    );
    this.frame.height = Math.min(
    this.frame.style.height =
      Math.min(
        Services.prefs.getIntPref(this.heightPref),
        this._browserContainer.clientHeight - MIN_PAGE_SIZE
    );
      ) + "px";

    this._browserContainer.appendChild(this._splitter);
    this._browserContainer.appendChild(this.frame);
@@ -104,7 +105,10 @@ BottomHost.prototype = {
    if (!this._destroyed) {
      this._destroyed = true;

      Services.prefs.setIntPref(this.heightPref, this.frame.height);
      Services.prefs.setIntPref(
        this.heightPref,
        parseInt(this.frame.style.height, 10)
      );
      this._browserContainer.removeChild(this._splitter);
      this._browserContainer.removeChild(this.frame);
      this.frame = null;
+3 −4
Original line number Diff line number Diff line
@@ -967,9 +967,8 @@ Toolbox.prototype = {
      this.webconsolePanel = this.doc.querySelector(
        "#toolbox-panel-webconsole"
      );
      this.webconsolePanel.height = Services.prefs.getIntPref(
        SPLITCONSOLE_HEIGHT_PREF
      );
      this.webconsolePanel.style.height =
        Services.prefs.getIntPref(SPLITCONSOLE_HEIGHT_PREF) + "px";
      this.webconsolePanel.addEventListener(
        "resize",
        this._saveSplitConsoleHeight
@@ -1730,7 +1729,7 @@ Toolbox.prototype = {
  _saveSplitConsoleHeight() {
    Services.prefs.setIntPref(
      SPLITCONSOLE_HEIGHT_PREF,
      this.webconsolePanel.height
      parseInt(this.webconsolePanel.style.height, 10)
    );
  },

+4 −4
Original line number Diff line number Diff line
@@ -35,10 +35,10 @@ add_task(async function() {

  is(
    parseInt(getHeightPrefValue(), 10),
    parseInt(toolbox.webconsolePanel.height, 10),
    parseInt(toolbox.webconsolePanel.style.height, 10),
    "Panel height matches the pref"
  );
  toolbox.webconsolePanel.height = 200;
  toolbox.webconsolePanel.style.height = "200px";

  await toolbox.destroy();

@@ -62,13 +62,13 @@ add_task(async function() {
    "Height is set based on panel height after closing"
  );

  toolbox.webconsolePanel.height = 1;
  toolbox.webconsolePanel.style.height = "1px";
  ok(
    toolbox.webconsolePanel.clientHeight > 1,
    "The actual height of the console is bound with a min height"
  );

  toolbox.webconsolePanel.height = 10000;
  toolbox.webconsolePanel.style.height = "10000px";
  ok(
    toolbox.webconsolePanel.clientHeight < 10000,
    "The actual height of the console is bound with a max height"
+9 −16
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "nsNameSpaceManager.h"
#include "nsScrollbarButtonFrame.h"
#include "nsIDOMEventListener.h"
#include "nsICSSDeclaration.h"
#include "nsFrameList.h"
#include "nsHTMLParts.h"
#include "mozilla/ComputedStyle.h"
@@ -36,6 +37,7 @@
#include "mozilla/MouseEvents.h"
#include "mozilla/PresShell.h"
#include "mozilla/UniquePtr.h"
#include "nsStyledElement.h"

using namespace mozilla;

@@ -851,34 +853,25 @@ void nsSplitterFrameInner::SetPreferredSize(nsBoxLayoutState& aState,
  nsMargin margin(0, 0, 0, 0);
  aChildBox->GetXULMargin(margin);

  RefPtr<nsAtom> attribute;

  if (aIsHorizontal) {
    pref -= (margin.left + margin.right);
    attribute = nsGkAtoms::width;
  } else {
    pref -= (margin.top + margin.bottom);
    attribute = nsGkAtoms::height;
  }

  nsIContent* content = aChildBox->GetContent();
  if (!content->IsElement()) {
  RefPtr element = nsStyledElement::FromNode(aChildBox->GetContent());
  if (!element) {
    return;
  }

  nsCOMPtr<nsICSSDeclaration> decl = element->Style();

  // set its preferred size.
  nsAutoString prefValue;
  nsAutoCString prefValue;
  prefValue.AppendInt(pref / aOnePixel);
  if (content->AsElement()->AttrValueIs(kNameSpaceID_None, attribute, prefValue,
                                        eCaseMatters)) {
    return;
  }
  prefValue.AppendLiteral("px");

  AutoWeakFrame weakBox(aChildBox);
  content->AsElement()->SetAttr(kNameSpaceID_None, attribute, prefValue, true);
  NS_ENSURE_TRUE_VOID(weakBox.IsAlive());
  aState.PresShell()->FrameNeedsReflow(aChildBox, IntrinsicDirty::StyleChange,
                                       NS_FRAME_IS_DIRTY);
  decl->SetProperty(aIsHorizontal ? "width"_ns : "height"_ns, prefValue, ""_ns, IgnoreErrors());
}

void nsSplitterFrameInner::AddRemoveSpace(nscoord aDiff,
+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ var previousWidth = 0, originalWidth = 0;
var loadInWindow = false;

function splitterCallback(adjustment) {
  var newWidth = Number($("leftbox").width); // getBoundingClientRect().width;
  var newWidth = parseInt($("leftbox").style.width); // getBoundingClientRect().width;
  var expectedWidth = previousWidth + adjustment;
  if (expectedWidth > $("splitterbox").getBoundingClientRect().width)
    expectedWidth = $("splitterbox").getBoundingClientRect().width - $("splitter").getBoundingClientRect().width;
@@ -283,9 +283,9 @@ SimpleTest.waitForFocus(runTests);
  </tooltip>

  <hbox id="splitterbox" style="margin-top: 5px;" onmousedown="this.setCapture()">
    <hbox id="leftbox" width="100" flex="1"/>
    <hbox id="leftbox" style="width: 100px" flex="1"/>
    <splitter id="splitter" width="5" height="5"/>
    <hbox id="rightbox" width="100" flex="1"/>
    <hbox id="rightbox" style="width: 100px" flex="1"/>
  </hbox>

  <vbox id="custom" width="10" height="10" onmousedown="this.setCapture(); cachedMouseDown = event;"/>