Bug 1348665 part 1 - Move a few nsView related methods from nsContainerFrame to nsIFrame/nsFrame (idempotent patch). r=dholbert

Views are used for PluginFrame which inherits nsFrame, not nsContainerFrame,
so it's more appropriate that these methods should live in nsIFrame/nsFrame.

MozReview-Commit-ID: 87EgCnkF5YT
This commit is contained in:
Mats Palmgren 2017-03-21 01:22:13 +01:00
Родитель c2591c2bd2
Коммит 48fe777dbb
8 изменённых файлов: 162 добавлений и 157 удалений

Просмотреть файл

@ -3242,7 +3242,7 @@ nsCSSFrameConstructor::InitializeSelectFrame(nsFrameConstructorState& aState,
}
if (aBuildCombobox) {
nsContainerFrame::CreateViewForFrame(scrollFrame, true);
nsFrame::CreateViewForFrame(scrollFrame, true);
}
BuildScrollFrame(aState, aContent, aStyleContext, scrolledFrame,
@ -3930,7 +3930,7 @@ nsCSSFrameConstructor::ConstructFrameFromItemInternal(FrameConstructionItem& aIt
} else {
InitAndRestoreFrame(aState, content, geometricParent, newFrame);
// See whether we need to create a view
nsContainerFrame::CreateViewForFrame(newFrame, false);
nsFrame::CreateViewForFrame(newFrame, false);
frameToAddToList = newFrame;
}

Просмотреть файл

@ -377,92 +377,6 @@ nsContainerFrame::PeekOffsetCharacter(bool aForward, int32_t* aOffset,
/////////////////////////////////////////////////////////////////////////////
// Helper member functions
static void
ReparentFrameViewTo(nsIFrame* aFrame,
nsViewManager* aViewManager,
nsView* aNewParentView,
nsView* aOldParentView)
{
if (aFrame->HasView()) {
#ifdef MOZ_XUL
if (aFrame->GetType() == nsGkAtoms::menuPopupFrame) {
// This view must be parented by the root view, don't reparent it.
return;
}
#endif
nsView* view = aFrame->GetView();
// Verify that the current parent view is what we think it is
//nsView* parentView;
//NS_ASSERTION(parentView == aOldParentView, "unexpected parent view");
aViewManager->RemoveChild(view);
// The view will remember the Z-order and other attributes that have been set on it.
nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(aNewParentView, aFrame);
aViewManager->InsertChild(aNewParentView, view, insertBefore, insertBefore != nullptr);
} else if (aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW) {
nsIFrame::ChildListIterator lists(aFrame);
for (; !lists.IsDone(); lists.Next()) {
// Iterate the child frames, and check each child frame to see if it has
// a view
nsFrameList::Enumerator childFrames(lists.CurrentList());
for (; !childFrames.AtEnd(); childFrames.Next()) {
ReparentFrameViewTo(childFrames.get(), aViewManager,
aNewParentView, aOldParentView);
}
}
}
}
void
nsContainerFrame::CreateViewForFrame(nsIFrame* aFrame,
bool aForce)
{
if (aFrame->HasView()) {
return;
}
// If we don't yet have a view, see if we need a view
if (!aForce && !aFrame->NeedsView()) {
// don't need a view
return;
}
nsView* parentView = aFrame->GetParent()->GetClosestView();
NS_ASSERTION(parentView, "no parent with view");
nsViewManager* viewManager = parentView->GetViewManager();
NS_ASSERTION(viewManager, "null view manager");
// Create a view
nsView* view = viewManager->CreateView(aFrame->GetRect(), parentView);
SyncFrameViewProperties(aFrame->PresContext(), aFrame, nullptr, view);
nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, aFrame);
// we insert this view 'above' the insertBefore view, unless insertBefore is null,
// in which case we want to call with aAbove == false to insert at the beginning
// in document order
viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nullptr);
// REVIEW: Don't create a widget for fixed-pos elements anymore.
// ComputeRepaintRegionForCopy will calculate the right area to repaint
// when we scroll.
// Reparent views on any child frames (or their descendants) to this
// view. We can just call ReparentFrameViewTo on this frame because
// we know this frame has no view, so it will crawl the children. Also,
// we know that any descendants with views must have 'parentView' as their
// parent view.
ReparentFrameViewTo(aFrame, viewManager, view, parentView);
// Remember our view
aFrame->SetView(view);
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
("nsContainerFrame::CreateViewForFrame: frame=%p view=%p",
aFrame, view));
}
/**
* Position the view associated with |aKidFrame|, if there is one. A
* container frame should call this method after positioning a frame,
@ -769,54 +683,6 @@ nsContainerFrame::SyncFrameViewAfterReflow(nsPresContext* aPresContext,
}
}
void
nsContainerFrame::SyncFrameViewProperties(nsPresContext* aPresContext,
nsIFrame* aFrame,
nsStyleContext* aStyleContext,
nsView* aView,
uint32_t aFlags)
{
NS_ASSERTION(!aStyleContext || aFrame->StyleContext() == aStyleContext,
"Wrong style context for frame?");
if (!aView) {
return;
}
nsViewManager* vm = aView->GetViewManager();
if (nullptr == aStyleContext) {
aStyleContext = aFrame->StyleContext();
}
// Make sure visibility is correct. This only affects nsSubdocumentFrame.
if (0 == (aFlags & NS_FRAME_NO_VISIBILITY) &&
!aFrame->SupportsVisibilityHidden()) {
// See if the view should be hidden or visible
vm->SetViewVisibility(aView,
aStyleContext->StyleVisibility()->IsVisible()
? nsViewVisibility_kShow : nsViewVisibility_kHide);
}
int32_t zIndex = 0;
bool autoZIndex = false;
if (aFrame->IsAbsPosContainingBlock()) {
// Make sure z-index is correct
const nsStylePosition* position = aStyleContext->StylePosition();
if (position->mZIndex.GetUnit() == eStyleUnit_Integer) {
zIndex = position->mZIndex.GetIntValue();
} else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) {
autoZIndex = true;
}
} else {
autoZIndex = true;
}
vm->SetViewZIndex(aView, autoZIndex, zIndex);
}
static nscoord GetCoord(const nsStyleCoord& aCoord, nscoord aIfNotCoord)
{
if (aCoord.ConvertsToLength()) {

Просмотреть файл

@ -155,13 +155,6 @@ public:
virtual void DeleteNextInFlowChild(nsIFrame* aNextInFlow,
bool aDeletingEmptyFrames);
/**
* Helper method to wrap views around frames. Used by containers
* under special circumstances (can be used by leaf frames as well)
*/
static void CreateViewForFrame(nsIFrame* aFrame,
bool aForce);
// Positions the frame's view based on the frame's origin
static void PositionFrameView(nsIFrame* aKidFrame);
@ -198,18 +191,6 @@ public:
nsRenderingContext* aRC,
uint32_t aFlags);
// Sets the view's attributes from the frame style.
// - visibility
// - clip
// Call this when one of these styles changes or when the view has just
// been created.
// @param aStyleContext can be null, in which case the frame's style context is used
static void SyncFrameViewProperties(nsPresContext* aPresContext,
nsIFrame* aFrame,
nsStyleContext* aStyleContext,
nsView* aView,
uint32_t aFlags = 0);
/**
* Converts the minimum and maximum sizes given in inner window app units to
* outer window device pixel sizes and assigns these constraints to the widget.

Просмотреть файл

@ -986,6 +986,140 @@ nsFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
RemoveStateBits(NS_FRAME_SIMPLE_EVENT_REGIONS);
}
void
nsIFrame::ReparentFrameViewTo(nsIFrame* aFrame,
nsViewManager* aViewManager,
nsView* aNewParentView,
nsView* aOldParentView)
{
if (aFrame->HasView()) {
#ifdef MOZ_XUL
if (aFrame->GetType() == nsGkAtoms::menuPopupFrame) {
// This view must be parented by the root view, don't reparent it.
return;
}
#endif
nsView* view = aFrame->GetView();
// Verify that the current parent view is what we think it is
//nsView* parentView;
//NS_ASSERTION(parentView == aOldParentView, "unexpected parent view");
aViewManager->RemoveChild(view);
// The view will remember the Z-order and other attributes that have been set on it.
nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(aNewParentView, aFrame);
aViewManager->InsertChild(aNewParentView, view, insertBefore, insertBefore != nullptr);
} else if (aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW) {
nsIFrame::ChildListIterator lists(aFrame);
for (; !lists.IsDone(); lists.Next()) {
// Iterate the child frames, and check each child frame to see if it has
// a view
nsFrameList::Enumerator childFrames(lists.CurrentList());
for (; !childFrames.AtEnd(); childFrames.Next()) {
ReparentFrameViewTo(childFrames.get(), aViewManager,
aNewParentView, aOldParentView);
}
}
}
}
void
nsIFrame::SyncFrameViewProperties(nsPresContext* aPresContext,
nsIFrame* aFrame,
nsStyleContext* aStyleContext,
nsView* aView,
uint32_t aFlags)
{
NS_ASSERTION(!aStyleContext || aFrame->StyleContext() == aStyleContext,
"Wrong style context for frame?");
if (!aView) {
return;
}
nsViewManager* vm = aView->GetViewManager();
if (nullptr == aStyleContext) {
aStyleContext = aFrame->StyleContext();
}
// Make sure visibility is correct. This only affects nsSubdocumentFrame.
if (0 == (aFlags & NS_FRAME_NO_VISIBILITY) &&
!aFrame->SupportsVisibilityHidden()) {
// See if the view should be hidden or visible
vm->SetViewVisibility(aView,
aStyleContext->StyleVisibility()->IsVisible()
? nsViewVisibility_kShow : nsViewVisibility_kHide);
}
int32_t zIndex = 0;
bool autoZIndex = false;
if (aFrame->IsAbsPosContainingBlock()) {
// Make sure z-index is correct
const nsStylePosition* position = aStyleContext->StylePosition();
if (position->mZIndex.GetUnit() == eStyleUnit_Integer) {
zIndex = position->mZIndex.GetIntValue();
} else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) {
autoZIndex = true;
}
} else {
autoZIndex = true;
}
vm->SetViewZIndex(aView, autoZIndex, zIndex);
}
void
nsFrame::CreateViewForFrame(nsIFrame* aFrame,
bool aForce)
{
if (aFrame->HasView()) {
return;
}
// If we don't yet have a view, see if we need a view
if (!aForce && !aFrame->NeedsView()) {
// don't need a view
return;
}
nsView* parentView = aFrame->GetParent()->GetClosestView();
NS_ASSERTION(parentView, "no parent with view");
nsViewManager* viewManager = parentView->GetViewManager();
NS_ASSERTION(viewManager, "null view manager");
// Create a view
nsView* view = viewManager->CreateView(aFrame->GetRect(), parentView);
SyncFrameViewProperties(aFrame->PresContext(), aFrame, nullptr, view);
nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, aFrame);
// we insert this view 'above' the insertBefore view, unless insertBefore is null,
// in which case we want to call with aAbove == false to insert at the beginning
// in document order
viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nullptr);
// REVIEW: Don't create a widget for fixed-pos elements anymore.
// ComputeRepaintRegionForCopy will calculate the right area to repaint
// when we scroll.
// Reparent views on any child frames (or their descendants) to this
// view. We can just call ReparentFrameViewTo on this frame because
// we know this frame has no view, so it will crawl the children. Also,
// we know that any descendants with views must have 'parentView' as their
// parent view.
ReparentFrameViewTo(aFrame, viewManager, view, parentView);
// Remember our view
aFrame->SetView(view);
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
("nsContainerFrame::CreateViewForFrame: frame=%p view=%p",
aFrame, view));
}
// MSVC fails with link error "one or more multiply defined symbols found",
// gcc fails with "hidden symbol `nsIFrame::kPrincipalList' isn't defined"
// etc if they are not defined.

Просмотреть файл

@ -595,6 +595,13 @@ protected:
void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
public:
/**
* Helper method to wrap views around frames. Used by containers
* under special circumstances (can be used by leaf frames as well)
*/
static void CreateViewForFrame(nsIFrame* aFrame,
bool aForce);
//given a frame five me the first/last leaf available
//XXX Robert O'Callahan wants to move these elsewhere
static void GetLastLeaf(nsPresContext* aPresContext, nsIFrame **aFrame);

Просмотреть файл

@ -2466,6 +2466,18 @@ public:
*/
nsIFrame* GetAncestorWithView() const;
// Sets the view's attributes from the frame style.
// - visibility
// - clip
// Call this when one of these styles changes or when the view has just
// been created.
// @param aStyleContext can be null, in which case the frame's style context is used
static void SyncFrameViewProperties(nsPresContext* aPresContext,
nsIFrame* aFrame,
nsStyleContext* aStyleContext,
nsView* aView,
uint32_t aFlags = 0);
/**
* Get the offset between the coordinate systems of |this| and aOther.
* Adding the return value to a point in the coordinate system of |this|
@ -3616,6 +3628,11 @@ public:
const nsStyleCoord& aCoord,
ComputeSizeFlags aFlags = eDefault);
protected:
static void ReparentFrameViewTo(nsIFrame* aFrame,
nsViewManager* aViewManager,
nsView* aNewParentView,
nsView* aOldParentView);
// Members
nsRect mRect;
nsIContent* mContent;

Просмотреть файл

@ -130,7 +130,7 @@ nsSubDocumentFrame::Init(nsIContent* aContent,
// really need it or not, and the inner view will get it as the
// parent.
if (!HasView()) {
nsContainerFrame::CreateViewForFrame(this, true);
nsFrame::CreateViewForFrame(this, true);
}
EnsureInnerView();

Просмотреть файл

@ -2436,7 +2436,7 @@ nsMenuPopupFrame::GetAlignmentPosition() const
}
/**
* KEEP THIS IN SYNC WITH nsContainerFrame::CreateViewForFrame
* KEEP THIS IN SYNC WITH nsFrame::CreateView
* as much as possible. Until we get rid of views finally...
*/
void