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

Side by Side Diff: chrome/browser/views/frame/contents_container.cc

Issue 3332022: Bunch of match preview tweaks: (Closed)
Patch Set: Add string16 include Created 10 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/views/frame/contents_container.h"
6
7 #include "app/resource_bundle.h"
8 #include "chrome/browser/location_bar.h"
9 #include "chrome/browser/views/frame/browser_view.h"
10 #include "grit/theme_resources.h"
11 #include "views/controls/image_view.h"
12 #include "views/widget/root_view.h"
13
14 #if defined(OS_WIN)
15 #include "views/widget/widget_win.h"
16 #elif defined(OS_LINUX)
17 #include "chrome/browser/gtk/gtk_util.h"
18 #include "views/window/window_gtk.h"
19 #endif
20
21 #if defined(OS_WIN)
22
23 class ContentsContainer::TearWindow : public views::WidgetWin {
24 public:
25 explicit TearWindow(ContentsContainer* contents_container)
26 : contents_container_(contents_container) {
27 set_window_style(WS_POPUP | WS_CLIPCHILDREN);
28 set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED);
29 }
30
31 virtual ~TearWindow() {
32 // On windows it's possible for us to be deleted before the
33 // ContentsContainer. If this happens make sure contents_container_ doesn't
34 // attempt to delete us too.
35 if (contents_container_)
36 contents_container_->TearWindowDestroyed();
37 }
38
39 void set_contents_container(ContentsContainer* contents_container) {
40 contents_container_ = contents_container;
41 }
42
43 virtual LRESULT OnMouseActivate(HWND window,
44 UINT hit_test,
45 UINT mouse_message) {
46 // Don't activate the window when the user clicks it.
47 contents_container_->browser_view_->GetLocationBar()->Revert();
48 return MA_NOACTIVATE;
49 }
50
51 private:
52 ContentsContainer* contents_container_;
53
54 DISALLOW_COPY_AND_ASSIGN(TearWindow);
55 };
56
57 #endif
58
59 ContentsContainer::ContentsContainer(BrowserView* browser_view,
60 views::View* active)
61 : browser_view_(browser_view),
62 active_(active),
63 preview_(NULL),
64 preview_tab_contents_(NULL),
65 tear_window_(NULL),
66 active_top_margin_(0) {
67 AddChildView(active_);
68 }
69
70 ContentsContainer::~ContentsContainer() {
71 DeleteTearWindow();
72 }
73
74 void ContentsContainer::MakePreviewContentsActiveContents() {
75 active_ = preview_;
76 preview_ = NULL;
77 DeleteTearWindow();
78 Layout();
79 }
80
81 void ContentsContainer::SetPreview(views::View* preview,
82 TabContents* preview_tab_contents) {
83 if (preview == preview_)
84 return;
85
86 if (preview_) {
87 RemoveChildView(preview_);
88 DeleteTearWindow();
89 }
90 preview_ = preview;
91 preview_tab_contents_ = preview_tab_contents;
92 if (preview_) {
93 AddChildView(preview_);
94 CreateTearWindow();
95 }
96
97 Layout();
98
99 if (preview_)
100 tear_window_->Show(); // Show after we'ved positioned it in Layout.
101 }
102
103 void ContentsContainer::SetActiveTopMargin(int margin) {
104 if (active_top_margin_ == margin)
105 return;
106
107 active_top_margin_ = margin;
108 // Make sure we layout next time around. We need this in case our bounds
109 // haven't changed.
110 InvalidateLayout();
111 }
112
113 void ContentsContainer::Layout() {
114 // The active view always gets the full bounds.
115 active_->SetBounds(0, active_top_margin_, width(),
116 std::max(0, height() - active_top_margin_));
117
118 if (preview_) {
119 preview_->SetBounds(0, 0, width(), height());
120 PositionTearWindow();
121 }
122
123 // Need to invoke views::View in case any views whose bounds didn't change
124 // still need a layout.
125 views::View::Layout();
126 }
127
128 void ContentsContainer::CreateTearWindow() {
129 DCHECK(preview_);
130 tear_window_ = CreateTearWindowImpl();
131
132 views::ImageView* image_view = new views::ImageView();
133 image_view->SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed(
134 IDR_MATCH_PREVIEW_TEAR));
135 tear_window_->SetContentsView(image_view);
136 }
137
138 #if defined(OS_WIN)
139
140 ContentsContainer::TearWindow* ContentsContainer::CreateTearWindowImpl() {
141 TearWindow* widget = new TearWindow(this);
142 widget->Init(browser_view_->GetNativeHandle(), gfx::Rect());
143 return widget;
144 }
145
146 #elif defined(OS_LINUX)
147
148 ContentsContainer::TearWindow* ContentsContainer::CreateTearWindowImpl() {
149 views::WidgetGtk* widget = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP);
150 widget->MakeTransparent();
151 widget->Init(NULL, gfx::Rect());
152 gtk_util::StackPopupWindow(widget->GetNativeView(),
153 GTK_WIDGET(browser_view_->GetNativeHandle()));
154 return widget;
155 }
156
157 #endif
158
159 void ContentsContainer::PositionTearWindow() {
160 if (!tear_window_)
161 return;
162
163 gfx::Rect vis_bounds = GetVisibleBounds();
164
165 gfx::Size pref = tear_window_->GetRootView()->GetPreferredSize();
166 // Constrain to the the visible bounds as we may be given a different size
167 // than is actually visible.
168 pref.SetSize(std::min(pref.width(), vis_bounds.width()),
169 std::min(pref.height(), vis_bounds.height()));
170
171 gfx::Rect bounds(0, 0, pref.width(), pref.height());
172 bounds.set_x(MirroredLeftPointForRect(bounds));
173
174 gfx::Point origin(bounds.origin());
175 views::View::ConvertPointToScreen(this, &origin);
176
177 tear_window_->SetBounds(gfx::Rect(origin, pref));
178 }
179
180 void ContentsContainer::DeleteTearWindow() {
181 if (!tear_window_)
182 return;
183
184 tear_window_->Close();
185 #if defined(OS_WIN)
186 tear_window_->set_contents_container(NULL);
187 #endif
188 // Close deletes the tear window.
189 tear_window_ = NULL;
190 }
191
192 void ContentsContainer::TearWindowDestroyed() {
193 tear_window_ = NULL;
194 }
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/contents_container.h ('k') | chrome/browser/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698