Delete unused downloads page asset.
[chromium-blink-merge.git] / mandoline / tab / frame_tree.cc
blob0ef0e439040d6ac9c069e8a33043c36214093ae0
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"
10 namespace mandoline {
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)
17 : view_(view),
18 delegate_(delegate),
19 root_(this,
20 view,
21 view->id(),
22 ViewOwnership::DOESNT_OWN_VIEW,
23 root_client,
24 user_data.Pass(),
25 client_properties),
26 progress_(0.f),
27 change_id_(1u) {
28 root_.Init(nullptr);
31 FrameTree::~FrameTree() {
34 Frame* FrameTree::CreateAndAddFrame(mojo::View* view,
35 Frame* parent,
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(
43 Frame* parent,
44 uint32_t frame_id,
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,
50 client_properties);
53 uint32_t FrameTree::AdvanceChangeID() {
54 return ++change_id_;
57 Frame* FrameTree::CreateAndAddFrameImpl(
58 mojo::View* view,
59 uint32_t frame_id,
60 Frame* parent,
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);
66 frame->Init(parent);
67 return frame;
70 void FrameTree::LoadingStateChanged() {
71 bool loading = root_.IsLoading();
72 if (delegate_)
73 delegate_->LoadingStateChanged(loading);
76 void FrameTree::ProgressChanged() {
77 int frame_count = 0;
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);
82 if (delegate_)
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