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
,
16 const Frame::ClientPropertyMap
& client_properties
)
22 ViewOwnership::DOESNT_OWN_VIEW
,
31 FrameTree::~FrameTree() {
34 Frame
* FrameTree::CreateAndAddFrame(mojo::View
* view
,
36 FrameTreeClient
* client
,
37 scoped_ptr
<FrameUserData
> user_data
) {
38 return CreateAndAddFrameImpl(view
, view
->id(), parent
, client
,
39 user_data
.Pass(), Frame::ClientPropertyMap());
42 void FrameTree::CreateSharedFrame(
45 const Frame::ClientPropertyMap
& client_properties
) {
46 mojo::View
* frame_view
= root_
.view()->GetChildById(frame_id
);
47 // |frame_view| may be null if the View hasn't been created yet. If this is
48 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
49 CreateAndAddFrameImpl(frame_view
, frame_id
, parent
, nullptr, nullptr,
53 uint32_t FrameTree::AdvanceChangeID() {
57 Frame
* FrameTree::CreateAndAddFrameImpl(
61 FrameTreeClient
* client
,
62 scoped_ptr
<FrameUserData
> user_data
,
63 const Frame::ClientPropertyMap
& client_properties
) {
64 Frame
* frame
= new Frame(this, view
, frame_id
, ViewOwnership::OWNS_VIEW
,
65 client
, user_data
.Pass(), client_properties
);
70 void FrameTree::LoadingStateChanged() {
71 bool loading
= root_
.IsLoading();
73 delegate_
->LoadingStateChanged(loading
);
76 void FrameTree::ProgressChanged() {
78 double total_progress
= root_
.GatherProgress(&frame_count
);
79 // Make sure the progress bar never runs backwards, even if that means
80 // accuracy takes a hit.
81 progress_
= std::max(progress_
, total_progress
/ frame_count
);
83 delegate_
->ProgressChanged(progress_
);
86 void FrameTree::ClientPropertyChanged(const Frame
* source
,
87 const mojo::String
& name
,
88 const mojo::Array
<uint8_t>& value
) {
89 root_
.NotifyClientPropertyChanged(source
, name
, value
);
92 } // namespace mandoline