Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mandoline / tab / frame_tree.cc
bloba3387deea7eae3951ba89433f69850dc87f942c2
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 : view_(view),
17 delegate_(delegate),
18 root_(this,
19 view,
20 view->id(),
21 ViewOwnership::DOESNT_OWN_VIEW,
22 root_client,
23 user_data.Pass()),
24 progress_(0.f) {
25 root_.Init(nullptr);
28 FrameTree::~FrameTree() {
31 Frame* FrameTree::CreateAndAddFrame(mojo::View* view,
32 Frame* parent,
33 FrameTreeClient* client,
34 scoped_ptr<FrameUserData> user_data) {
35 return CreateAndAddFrameImpl(view, view->id(), parent, client,
36 user_data.Pass());
39 Frame* FrameTree::CreateOrReplaceFrame(Frame* frame,
40 mojo::View* view,
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();
50 delete frame;
51 frame = nullptr;
52 } // else case is a view is becoming associated with a Frame, eg a new frame.
54 DCHECK(parent);
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,
67 uint32_t frame_id,
68 Frame* parent,
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());
73 frame->Init(parent);
74 return frame;
77 void FrameTree::LoadingStateChanged() {
78 bool loading = root_.IsLoading();
79 if (delegate_)
80 delegate_->LoadingStateChanged(loading);
83 void FrameTree::ProgressChanged() {
84 int frame_count = 0;
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);
89 if (delegate_)
90 delegate_->ProgressChanged(progress_);
93 void FrameTree::FrameNameChanged(Frame* frame) {
94 root_.NotifyFrameNameChanged(frame);
97 } // namespace mandoline