Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1771)

Side by Side Diff: chrome/browser/ui/views/panels/panel_stack_view.cc

Issue 11669018: Support dragging panels to stack and snap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change per feedback Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "chrome/browser/ui/views/panels/panel_stack_view.h"
6
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/panels/panel.h"
11 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
12 #include "chrome/common/extensions/extension.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/views/widget/widget.h"
15
16 #if defined(OS_WIN)
17 #include "chrome/browser/shell_integration.h"
18 #include "ui/base/win/shell.h"
19 #endif
20
21 // static
22 NativePanelStack* NativePanelStack::Create(StackedPanelCollection* stack) {
23 #if defined(OS_WIN)
24 return new PanelStackView(stack);
25 #else
26 NOTIMPLEMENTED();
27 return NULL;
28 #endif
29 }
30
31 PanelStackView::PanelStackView(StackedPanelCollection* stack)
32 : stack_(stack),
33 delay_initialized_(false),
34 window_(NULL) {
35 window_ = new views::Widget;
36 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
37 params.delegate = this;
38 params.remove_standard_frame = true;
39 params.transparent = true;
40 // Empty size is not allowed so a temporary small size is passed. SetBounds
41 // will be called later to update the bounds.
42 params.bounds = gfx::Rect(0, 0, 1, 1);
43 window_->Init(params);
44 window_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
45 window_->set_focus_on_creation(false);
46 window_->AddObserver(this);
47 window_->ShowInactive();
48 }
49
50 PanelStackView::~PanelStackView() {
51 }
52
53 void PanelStackView::Close() {
54 stack_.reset();
55 window_->Close();
56 }
57
58 void PanelStackView::OnPanelAddedOrRemoved() {
59 // The stack view cannot be fully initialized until the first panel has been
60 // added to the stack because we need the information from that panel.
61 if (delay_initialized_)
62 return;
63 Panel* panel = stack_->top_panel();
64 if (!panel)
65 return;
66 delay_initialized_ = true;
67
68 #if defined(OS_WIN) && !defined(USE_AURA)
69 ui::win::SetAppIdForWindow(
70 ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(panel->app_name()),
71 panel->profile()->GetPath()),
72 window_->GetNativeWindow());
73 #endif
74
75 window_->UpdateWindowTitle();
76 window_->UpdateWindowIcon();
77 }
78
79 gfx::NativeWindow PanelStackView::GetNativeWindow() const {
80 return window_->GetNativeWindow();
81 }
82
83 void PanelStackView::SetBounds(const gfx::Rect& bounds) {
84 window_->SetBounds(bounds);
85 }
86
87 string16 PanelStackView::GetWindowTitle() const {
88 Panel* panel = stack_->top_panel();
89 if (!panel)
90 return string16();
91
92 const extensions::Extension* extension = panel->GetExtension();
93 return UTF8ToUTF16(extension && !extension->name().empty() ?
94 extension->name() : panel->app_name());
95 }
96
97 gfx::ImageSkia PanelStackView::GetWindowAppIcon() {
98 Panel* panel = stack_->top_panel();
99 if (panel) {
100 gfx::Image app_icon = panel->app_icon();
101 if (!app_icon.IsEmpty())
102 return *app_icon.ToImageSkia();
103 }
104 return gfx::ImageSkia();
105 }
106
107 gfx::ImageSkia PanelStackView::GetWindowIcon() {
108 return GetWindowAppIcon();
109 }
110
111 views::Widget* PanelStackView::GetWidget() {
112 return window_;
113 }
114
115 const views::Widget* PanelStackView::GetWidget() const {
116 return window_;
117 }
118
119 void PanelStackView::OnWidgetClosing(views::Widget* widget) {
120 window_ = NULL;
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698