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 if (frame
->view() == view
) {
46 // It's important we Swap() here rather than destroy as otherwise the
47 // clients see a destroy followed by a new frame, which confuses html
49 DCHECK(frame
!= &root_
);
50 frame
->Swap(frame_tree_client
, user_data
.Pass());
54 return CreateAndAddFrame(view
, frame
, frame_tree_client
, user_data
.Pass());
57 void FrameTree::CreateSharedFrame(Frame
* parent
, uint32_t frame_id
) {
58 mojo::View
* frame_view
= root_
.view()->GetChildById(frame_id
);
59 // |frame_view| may be null if the View hasn't been created yet. If this is
60 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
61 CreateAndAddFrameImpl(frame_view
, frame_id
, parent
, nullptr, nullptr);
64 Frame
* FrameTree::CreateAndAddFrameImpl(mojo::View
* view
,
67 FrameTreeClient
* client
,
68 scoped_ptr
<FrameUserData
> user_data
) {
69 Frame
* frame
= new Frame(this, view
, frame_id
, ViewOwnership::OWNS_VIEW
,
70 client
, user_data
.Pass());
75 void FrameTree::LoadingStateChanged() {
76 bool loading
= root_
.IsLoading();
78 delegate_
->LoadingStateChanged(loading
);
81 void FrameTree::ProgressChanged() {
83 double total_progress
= root_
.GatherProgress(&frame_count
);
84 // Make sure the progress bar never runs backwards, even if that means
85 // accuracy takes a hit.
86 progress_
= std::max(progress_
, total_progress
/ frame_count
);
88 delegate_
->ProgressChanged(progress_
);
91 void FrameTree::FrameNameChanged(Frame
* frame
) {
92 root_
.NotifyFrameNameChanged(frame
);
95 } // namespace mandoline