1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mandoline/tab/frame_tree.h"
7 #include "mandoline/tab/frame_tree_delegate.h"
8 #include "mandoline/tab/frame_user_data.h"
12 FrameTree::FrameTree(mojo::View
* view
,
13 FrameTreeDelegate
* delegate
,
14 FrameTreeClient
* root_client
,
15 scoped_ptr
<FrameUserData
> user_data
)
21 ViewOwnership::DOESNT_OWN_VIEW
,
28 FrameTree::~FrameTree() {
31 Frame
* FrameTree::CreateAndAddFrame(mojo::View
* view
,
33 FrameTreeClient
* client
,
34 scoped_ptr
<FrameUserData
> user_data
) {
35 return CreateAndAddFrameImpl(view
, view
->id(), parent
, client
,
39 Frame
* FrameTree::CreateOrReplaceFrame(Frame
* frame
,
41 FrameTreeClient
* frame_tree_client
,
42 scoped_ptr
<FrameUserData
> user_data
) {
43 DCHECK(frame
&& frame
->HasAncestor(&root_
));
45 Frame
* parent
= frame
;
46 if (frame
->view() == view
) {
47 DCHECK(frame
!= &root_
);
48 // Rembed in existing frame.
49 parent
= frame
->parent();
52 } // else case is a view is becoming associated with a Frame, eg a new frame.
56 return CreateAndAddFrame(view
, parent
, frame_tree_client
, user_data
.Pass());
59 void FrameTree::CreateSharedFrame(Frame
* parent
, uint32_t frame_id
) {
60 mojo::View
* frame_view
= root_
.view()->GetChildById(frame_id
);
61 // |frame_view| may be null if the View hasn't been created yet. If this is
62 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
63 CreateAndAddFrameImpl(frame_view
, frame_id
, parent
, nullptr, nullptr);
66 Frame
* FrameTree::CreateAndAddFrameImpl(mojo::View
* view
,
69 FrameTreeClient
* client
,
70 scoped_ptr
<FrameUserData
> user_data
) {
71 Frame
* frame
= new Frame(this, view
, frame_id
, ViewOwnership::OWNS_VIEW
,
72 client
, user_data
.Pass());
77 void FrameTree::LoadingStateChanged() {
78 bool loading
= root_
.IsLoading();
80 delegate_
->LoadingStateChanged(loading
);
83 void FrameTree::ProgressChanged() {
85 double total_progress
= root_
.GatherProgress(&frame_count
);
86 // Make sure the progress bar never runs backwards, even if that means
87 // accuracy takes a hit.
88 progress_
= std::max(progress_
, total_progress
/ frame_count
);
90 delegate_
->ProgressChanged(progress_
);
93 void FrameTree::FrameNameChanged(Frame
* frame
) {
94 root_
.NotifyFrameNameChanged(frame
);
97 } // namespace mandoline