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

Side by Side Diff: chrome/browser/ui/views/extensions/shell_window_views.cc

Issue 10822004: Draggable region support for frameless app window on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 8 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/extensions/shell_window_views.h" 5 #include "chrome/browser/ui/views/extensions/shell_window_views.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/common/extensions/extension.h" 9 #include "chrome/common/extensions/extension.h"
10 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_widget_host_view.h" 11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h" 13 #include "content/public/browser/web_contents_view.h"
14 #include "content/public/common/draggable_region.h"
14 #include "grit/ui_resources.h" 15 #include "grit/ui_resources.h"
15 #include "grit/ui_strings.h" // Accessibility names 16 #include "grit/ui_strings.h" // Accessibility names
16 #include "third_party/skia/include/core/SkPaint.h" 17 #include "third_party/skia/include/core/SkPaint.h"
17 #include "ui/base/hit_test.h" 18 #include "ui/base/hit_test.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "ui/gfx/path.h" 23 #include "ui/gfx/path.h"
23 #include "ui/gfx/scoped_sk_region.h"
24 #include "ui/views/controls/button/button.h" 24 #include "ui/views/controls/button/button.h"
25 #include "ui/views/controls/button/image_button.h" 25 #include "ui/views/controls/button/image_button.h"
26 #include "ui/views/controls/webview/webview.h" 26 #include "ui/views/controls/webview/webview.h"
27 #include "ui/views/layout/grid_layout.h" 27 #include "ui/views/layout/grid_layout.h"
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 #include "ui/views/window/non_client_view.h" 29 #include "ui/views/window/non_client_view.h"
30 30
31 #if defined(OS_WIN) && !defined(USE_AURA) 31 #if defined(OS_WIN) && !defined(USE_AURA)
32 #include "chrome/browser/shell_integration.h" 32 #include "chrome/browser/shell_integration.h"
33 #include "chrome/browser/web_applications/web_app.h" 33 #include "chrome/browser/web_applications/web_app.h"
(...skipping 22 matching lines...) Expand all
56 56
57 // Height of the chrome-style caption, in pixels. 57 // Height of the chrome-style caption, in pixels.
58 const int kCaptionHeight = 25; 58 const int kCaptionHeight = 25;
59 } // namespace 59 } // namespace
60 60
61 class ShellWindowFrameView : public views::NonClientFrameView, 61 class ShellWindowFrameView : public views::NonClientFrameView,
62 public views::ButtonListener { 62 public views::ButtonListener {
63 public: 63 public:
64 static const char kViewClassName[]; 64 static const char kViewClassName[];
65 65
66 explicit ShellWindowFrameView(bool frameless); 66 explicit ShellWindowFrameView(ShellWindowViews* window);
67 virtual ~ShellWindowFrameView(); 67 virtual ~ShellWindowFrameView();
68 68
69 void Init(views::Widget* frame); 69 void Init(views::Widget* frame);
70 70
71 // views::NonClientFrameView implementation. 71 // views::NonClientFrameView implementation.
72 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 72 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
73 virtual gfx::Rect GetWindowBoundsForClientBounds( 73 virtual gfx::Rect GetWindowBoundsForClientBounds(
74 const gfx::Rect& client_bounds) const OVERRIDE; 74 const gfx::Rect& client_bounds) const OVERRIDE;
75 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 75 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
76 virtual void GetWindowMask(const gfx::Size& size, 76 virtual void GetWindowMask(const gfx::Size& size,
77 gfx::Path* window_mask) OVERRIDE; 77 gfx::Path* window_mask) OVERRIDE;
78 virtual void ResetWindowControls() OVERRIDE {} 78 virtual void ResetWindowControls() OVERRIDE {}
79 virtual void UpdateWindowIcon() OVERRIDE {} 79 virtual void UpdateWindowIcon() OVERRIDE {}
80 80
81 // views::View implementation. 81 // views::View implementation.
82 virtual gfx::Size GetPreferredSize() OVERRIDE; 82 virtual gfx::Size GetPreferredSize() OVERRIDE;
83 virtual void Layout() OVERRIDE; 83 virtual void Layout() OVERRIDE;
84 virtual std::string GetClassName() const OVERRIDE; 84 virtual std::string GetClassName() const OVERRIDE;
85 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 85 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
86 virtual gfx::Size GetMinimumSize() OVERRIDE; 86 virtual gfx::Size GetMinimumSize() OVERRIDE;
87 virtual gfx::Size GetMaximumSize() OVERRIDE; 87 virtual gfx::Size GetMaximumSize() OVERRIDE;
88 88
89 private: 89 private:
90 // views::ButtonListener implementation. 90 // views::ButtonListener implementation.
91 virtual void ButtonPressed(views::Button* sender, const views::Event& event) 91 virtual void ButtonPressed(views::Button* sender, const views::Event& event)
92 OVERRIDE; 92 OVERRIDE;
93 93
94 ShellWindowViews* window_;
94 views::Widget* frame_; 95 views::Widget* frame_;
95 views::ImageButton* close_button_; 96 views::ImageButton* close_button_;
96 97
97 bool is_frameless_;
98
99 DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView); 98 DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView);
100 }; 99 };
101 100
102 const char ShellWindowFrameView::kViewClassName[] = 101 const char ShellWindowFrameView::kViewClassName[] =
103 "browser/ui/views/extensions/ShellWindowFrameView"; 102 "browser/ui/views/extensions/ShellWindowFrameView";
104 103
105 ShellWindowFrameView::ShellWindowFrameView(bool frameless) 104 ShellWindowFrameView::ShellWindowFrameView(ShellWindowViews* window)
106 : frame_(NULL), 105 : window_(window),
107 close_button_(NULL), 106 close_button_(NULL) {
108 is_frameless_(frameless) {
109 } 107 }
110 108
111 ShellWindowFrameView::~ShellWindowFrameView() { 109 ShellWindowFrameView::~ShellWindowFrameView() {
112 } 110 }
113 111
114 void ShellWindowFrameView::Init(views::Widget* frame) { 112 void ShellWindowFrameView::Init(views::Widget* frame) {
115 frame_ = frame; 113 frame_ = frame;
116 114
117 if (!is_frameless_) { 115 if (!window_->frameless()) {
118 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 116 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
119 close_button_ = new views::ImageButton(this); 117 close_button_ = new views::ImageButton(this);
120 close_button_->SetImage(views::CustomButton::BS_NORMAL, 118 close_button_->SetImage(views::CustomButton::BS_NORMAL,
121 rb.GetNativeImageNamed(IDR_CLOSE_BAR).ToImageSkia()); 119 rb.GetNativeImageNamed(IDR_CLOSE_BAR).ToImageSkia());
122 close_button_->SetImage(views::CustomButton::BS_HOT, 120 close_button_->SetImage(views::CustomButton::BS_HOT,
123 rb.GetNativeImageNamed(IDR_CLOSE_BAR_H).ToImageSkia()); 121 rb.GetNativeImageNamed(IDR_CLOSE_BAR_H).ToImageSkia());
124 close_button_->SetImage(views::CustomButton::BS_PUSHED, 122 close_button_->SetImage(views::CustomButton::BS_PUSHED,
125 rb.GetNativeImageNamed(IDR_CLOSE_BAR_P).ToImageSkia()); 123 rb.GetNativeImageNamed(IDR_CLOSE_BAR_P).ToImageSkia());
126 close_button_->SetAccessibleName( 124 close_button_->SetAccessibleName(
127 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); 125 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
(...skipping 11 matching lines...) Expand all
139 -outside_bounds, -outside_bounds)); 137 -outside_bounds, -outside_bounds));
140 // Ensure we get resize cursors just inside our bounds as well. 138 // Ensure we get resize cursors just inside our bounds as well.
141 // TODO(jeremya): do we need to update these when in fullscreen/maximized? 139 // TODO(jeremya): do we need to update these when in fullscreen/maximized?
142 window->set_hit_test_bounds_override_inner( 140 window->set_hit_test_bounds_override_inner(
143 gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize, 141 gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize,
144 kResizeInsideBoundsSize, kResizeInsideBoundsSize)); 142 kResizeInsideBoundsSize, kResizeInsideBoundsSize));
145 #endif 143 #endif
146 } 144 }
147 145
148 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { 146 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const {
149 if (is_frameless_ || frame_->IsFullscreen()) 147 if (window_->frameless() || frame_->IsFullscreen())
150 return bounds(); 148 return bounds();
151 return gfx::Rect(0, kCaptionHeight, width(), 149 return gfx::Rect(0, kCaptionHeight, width(),
152 std::max(0, height() - kCaptionHeight)); 150 std::max(0, height() - kCaptionHeight));
153 } 151 }
154 152
155 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds( 153 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds(
156 const gfx::Rect& client_bounds) const { 154 const gfx::Rect& client_bounds) const {
157 if (is_frameless_) 155 if (window_->frameless())
158 return client_bounds; 156 return client_bounds;
159 157
160 int closeButtonOffsetX = 158 int closeButtonOffsetX =
161 (kCaptionHeight - close_button_->height()) / 2; 159 (kCaptionHeight - close_button_->height()) / 2;
162 int header_width = close_button_->width() + closeButtonOffsetX * 2; 160 int header_width = close_button_->width() + closeButtonOffsetX * 2;
163 return gfx::Rect(client_bounds.x(), 161 return gfx::Rect(client_bounds.x(),
164 std::max(0, client_bounds.y() - kCaptionHeight), 162 std::max(0, client_bounds.y() - kCaptionHeight),
165 std::max(header_width, client_bounds.width()), 163 std::max(header_width, client_bounds.width()),
166 client_bounds.height() + kCaptionHeight); 164 client_bounds.height() + kCaptionHeight);
167 } 165 }
(...skipping 24 matching lines...) Expand all
192 kResizeInsideBoundsSize; 190 kResizeInsideBoundsSize;
193 int frame_component = GetHTComponentForFrame(point, 191 int frame_component = GetHTComponentForFrame(point,
194 resize_border, 192 resize_border,
195 resize_border, 193 resize_border,
196 kResizeAreaCornerSize, 194 kResizeAreaCornerSize,
197 kResizeAreaCornerSize, 195 kResizeAreaCornerSize,
198 can_ever_resize); 196 can_ever_resize);
199 if (frame_component != HTNOWHERE) 197 if (frame_component != HTNOWHERE)
200 return frame_component; 198 return frame_component;
201 199
200 // Check for possible draggable region in the client area for the frameless
201 // window.
202 if (window_->frameless() &&
203 window_->draggable_region() &&
204 window_->draggable_region()->contains(point.x(), point.y()))
205 return HTCAPTION;
206
202 int client_component = frame_->client_view()->NonClientHitTest(point); 207 int client_component = frame_->client_view()->NonClientHitTest(point);
203 if (client_component != HTNOWHERE) 208 if (client_component != HTNOWHERE)
204 return client_component; 209 return client_component;
205 210
206 // Then see if the point is within any of the window controls. 211 // Then see if the point is within any of the window controls.
207 if (close_button_->visible() && 212 if (close_button_->visible() &&
jeremya 2012/08/07 01:00:17 Unrelated to your change, but we really should che
jianli 2012/08/07 20:38:06 Done.
208 close_button_->GetMirroredBounds().Contains(point)) 213 close_button_->GetMirroredBounds().Contains(point))
209 return HTCLOSE; 214 return HTCLOSE;
210 215
211 // Caption is a safe default. 216 // Caption is a safe default.
212 return HTCAPTION; 217 return HTCAPTION;
213 } 218 }
214 219
215 void ShellWindowFrameView::GetWindowMask(const gfx::Size& size, 220 void ShellWindowFrameView::GetWindowMask(const gfx::Size& size,
216 gfx::Path* window_mask) { 221 gfx::Path* window_mask) {
217 // We got nothing to say about no window mask. 222 // We got nothing to say about no window mask.
218 } 223 }
219 224
220 gfx::Size ShellWindowFrameView::GetPreferredSize() { 225 gfx::Size ShellWindowFrameView::GetPreferredSize() {
221 gfx::Size pref = frame_->client_view()->GetPreferredSize(); 226 gfx::Size pref = frame_->client_view()->GetPreferredSize();
222 gfx::Rect bounds(0, 0, pref.width(), pref.height()); 227 gfx::Rect bounds(0, 0, pref.width(), pref.height());
223 return frame_->non_client_view()->GetWindowBoundsForClientBounds( 228 return frame_->non_client_view()->GetWindowBoundsForClientBounds(
224 bounds).size(); 229 bounds).size();
225 } 230 }
226 231
227 void ShellWindowFrameView::Layout() { 232 void ShellWindowFrameView::Layout() {
228 if (is_frameless_) 233 if (window_->frameless())
229 return; 234 return;
230 gfx::Size close_size = close_button_->GetPreferredSize(); 235 gfx::Size close_size = close_button_->GetPreferredSize();
231 int closeButtonOffsetY = 236 int closeButtonOffsetY =
232 (kCaptionHeight - close_size.height()) / 2; 237 (kCaptionHeight - close_size.height()) / 2;
233 int closeButtonOffsetX = closeButtonOffsetY; 238 int closeButtonOffsetX = closeButtonOffsetY;
234 close_button_->SetBounds( 239 close_button_->SetBounds(
235 width() - closeButtonOffsetX - close_size.width(), 240 width() - closeButtonOffsetX - close_size.width(),
236 closeButtonOffsetY, 241 closeButtonOffsetY,
237 close_size.width(), 242 close_size.width(),
238 close_size.height()); 243 close_size.height());
239 } 244 }
240 245
241 void ShellWindowFrameView::OnPaint(gfx::Canvas* canvas) { 246 void ShellWindowFrameView::OnPaint(gfx::Canvas* canvas) {
242 if (is_frameless_) 247 if (window_->frameless())
243 return; 248 return;
244 // TODO(jeremya): different look for inactive? 249 // TODO(jeremya): different look for inactive?
245 SkPaint paint; 250 SkPaint paint;
246 paint.setAntiAlias(false); 251 paint.setAntiAlias(false);
247 paint.setStyle(SkPaint::kFill_Style); 252 paint.setStyle(SkPaint::kFill_Style);
248 paint.setColor(SK_ColorWHITE); 253 paint.setColor(SK_ColorWHITE);
249 gfx::Path path; 254 gfx::Path path;
250 const int radius = 1; 255 const int radius = 1;
251 path.moveTo(0, radius); 256 path.moveTo(0, radius);
252 path.lineTo(radius, 0); 257 path.lineTo(radius, 0);
253 path.lineTo(width() - radius - 1, 0); 258 path.lineTo(width() - radius - 1, 0);
254 path.lineTo(width(), radius + 1); 259 path.lineTo(width(), radius + 1);
255 path.lineTo(width(), kCaptionHeight); 260 path.lineTo(width(), kCaptionHeight);
256 path.lineTo(0, kCaptionHeight); 261 path.lineTo(0, kCaptionHeight);
257 path.close(); 262 path.close();
258 canvas->DrawPath(path, paint); 263 canvas->DrawPath(path, paint);
259 } 264 }
260 265
261 std::string ShellWindowFrameView::GetClassName() const { 266 std::string ShellWindowFrameView::GetClassName() const {
262 return kViewClassName; 267 return kViewClassName;
263 } 268 }
264 269
265 gfx::Size ShellWindowFrameView::GetMinimumSize() { 270 gfx::Size ShellWindowFrameView::GetMinimumSize() {
266 gfx::Size min_size = frame_->client_view()->GetMinimumSize(); 271 gfx::Size min_size = frame_->client_view()->GetMinimumSize();
267 if (is_frameless_) 272 if (window_->frameless())
268 return min_size; 273 return min_size;
269 274
270 // Ensure we can display the top of the caption area. 275 // Ensure we can display the top of the caption area.
271 gfx::Rect client_bounds = GetBoundsForClientView(); 276 gfx::Rect client_bounds = GetBoundsForClientView();
272 min_size.Enlarge(0, client_bounds.y()); 277 min_size.Enlarge(0, client_bounds.y());
273 // Ensure we have enough space for the window icon and buttons. We allow 278 // Ensure we have enough space for the window icon and buttons. We allow
274 // the title string to collapse to zero width. 279 // the title string to collapse to zero width.
275 int closeButtonOffsetX = 280 int closeButtonOffsetX =
276 (kCaptionHeight - close_button_->height()) / 2; 281 (kCaptionHeight - close_button_->height()) / 2;
277 int header_width = close_button_->width() + closeButtonOffsetX * 2; 282 int header_width = close_button_->width() + closeButtonOffsetX * 2;
278 if (header_width > min_size.width()) 283 if (header_width > min_size.width())
279 min_size.set_width(header_width); 284 min_size.set_width(header_width);
280 return min_size; 285 return min_size;
281 } 286 }
282 287
283 gfx::Size ShellWindowFrameView::GetMaximumSize() { 288 gfx::Size ShellWindowFrameView::GetMaximumSize() {
284 gfx::Size max_size = frame_->client_view()->GetMaximumSize(); 289 gfx::Size max_size = frame_->client_view()->GetMaximumSize();
285 if (is_frameless_) 290 if (window_->frameless())
286 return max_size; 291 return max_size;
287 292
288 if (!max_size.IsEmpty()) { 293 if (!max_size.IsEmpty()) {
289 gfx::Rect client_bounds = GetBoundsForClientView(); 294 gfx::Rect client_bounds = GetBoundsForClientView();
290 max_size.Enlarge(0, client_bounds.y()); 295 max_size.Enlarge(0, client_bounds.y());
291 } 296 }
292 return max_size; 297 return max_size;
293 } 298 }
294 299
295 void ShellWindowFrameView::ButtonPressed(views::Button* sender, 300 void ShellWindowFrameView::ButtonPressed(views::Button* sender,
296 const views::Event& event) { 301 const views::Event& event) {
297 DCHECK(!is_frameless_); 302 DCHECK(!window_->frameless());
298 if (sender == close_button_) 303 if (sender == close_button_)
299 frame_->Close(); 304 frame_->Close();
300 } 305 }
301 306
302 ShellWindowViews::ShellWindowViews(Profile* profile, 307 ShellWindowViews::ShellWindowViews(Profile* profile,
303 const extensions::Extension* extension, 308 const extensions::Extension* extension,
304 const GURL& url, 309 const GURL& url,
305 const ShellWindow::CreateParams& win_params) 310 const ShellWindow::CreateParams& win_params)
306 : ShellWindow(profile, extension, url), 311 : ShellWindow(profile, extension, url),
307 web_view_(NULL), 312 web_view_(NULL),
308 is_fullscreen_(false), 313 is_fullscreen_(false),
309 use_custom_frame_( 314 frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) {
310 win_params.frame == ShellWindow::CreateParams::FRAME_NONE) {
311 window_ = new views::Widget; 315 window_ = new views::Widget;
312 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 316 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
313 params.delegate = this; 317 params.delegate = this;
314 params.remove_standard_frame = true; 318 params.remove_standard_frame = true;
315 minimum_size_ = win_params.minimum_size; 319 minimum_size_ = win_params.minimum_size;
316 maximum_size_ = win_params.maximum_size; 320 maximum_size_ = win_params.maximum_size;
317 window_->Init(params); 321 window_->Init(params);
318 gfx::Rect window_bounds = 322 gfx::Rect window_bounds =
319 window_->non_client_view()->GetWindowBoundsForClientBounds( 323 window_->non_client_view()->GetWindowBoundsForClientBounds(
320 win_params.bounds); 324 win_params.bounds);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 441 }
438 442
439 void ShellWindowViews::Restore() { 443 void ShellWindowViews::Restore() {
440 window_->Restore(); 444 window_->Restore();
441 } 445 }
442 446
443 void ShellWindowViews::SetBounds(const gfx::Rect& bounds) { 447 void ShellWindowViews::SetBounds(const gfx::Rect& bounds) {
444 GetWidget()->SetBounds(bounds); 448 GetWidget()->SetBounds(bounds);
445 } 449 }
446 450
447 void ShellWindowViews::SetDraggableRegion(SkRegion* region) {
448 caption_region_.Set(region);
449 OnViewWasResized();
450 }
451
452 void ShellWindowViews::FlashFrame(bool flash) { 451 void ShellWindowViews::FlashFrame(bool flash) {
453 window_->FlashFrame(flash); 452 window_->FlashFrame(flash);
454 } 453 }
455 454
456 bool ShellWindowViews::IsAlwaysOnTop() const { 455 bool ShellWindowViews::IsAlwaysOnTop() const {
457 return false; 456 return false;
458 } 457 }
459 458
460 void ShellWindowViews::DeleteDelegate() { 459 void ShellWindowViews::DeleteDelegate() {
461 OnNativeClose(); 460 OnNativeClose();
462 } 461 }
463 462
464 bool ShellWindowViews::CanResize() const { 463 bool ShellWindowViews::CanResize() const {
465 return true; 464 return true;
466 } 465 }
467 466
468 bool ShellWindowViews::CanMaximize() const { 467 bool ShellWindowViews::CanMaximize() const {
469 return true; 468 return true;
470 } 469 }
471 470
472 views::View* ShellWindowViews::GetContentsView() { 471 views::View* ShellWindowViews::GetContentsView() {
473 return this; 472 return this;
474 } 473 }
475 474
476 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView( 475 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView(
477 views::Widget* widget) { 476 views::Widget* widget) {
478 ShellWindowFrameView* frame_view = 477 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this);
479 new ShellWindowFrameView(use_custom_frame_);
480 frame_view->Init(window_); 478 frame_view->Init(window_);
481 return frame_view; 479 return frame_view;
482 } 480 }
483 481
484 string16 ShellWindowViews::GetWindowTitle() const { 482 string16 ShellWindowViews::GetWindowTitle() const {
485 return GetTitle(); 483 return GetTitle();
486 } 484 }
487 485
488 views::Widget* ShellWindowViews::GetWidget() { 486 views::Widget* ShellWindowViews::GetWidget() {
489 return window_; 487 return window_;
(...skipping 11 matching lines...) Expand all
501 DCHECK(window_); 499 DCHECK(window_);
502 DCHECK(web_view_); 500 DCHECK(web_view_);
503 gfx::Size sz = web_view_->size(); 501 gfx::Size sz = web_view_->size();
504 int height = sz.height(), width = sz.width(); 502 int height = sz.height(), width = sz.width();
505 int radius = 1; 503 int radius = 1;
506 gfx::Path path; 504 gfx::Path path;
507 if (window_->IsMaximized() || window_->IsFullscreen()) { 505 if (window_->IsMaximized() || window_->IsFullscreen()) {
508 // Don't round the corners when the window is maximized or fullscreen. 506 // Don't round the corners when the window is maximized or fullscreen.
509 path.addRect(0, 0, width, height); 507 path.addRect(0, 0, width, height);
510 } else { 508 } else {
511 if (use_custom_frame_) { 509 if (frameless_) {
512 path.moveTo(0, radius); 510 path.moveTo(0, radius);
513 path.lineTo(radius, 0); 511 path.lineTo(radius, 0);
514 path.lineTo(width - radius, 0); 512 path.lineTo(width - radius, 0);
515 path.lineTo(width, radius); 513 path.lineTo(width, radius);
516 } else { 514 } else {
517 // Don't round the top corners in chrome-style frame mode. 515 // Don't round the top corners in chrome-style frame mode.
518 path.moveTo(0, 0); 516 path.moveTo(0, 0);
519 path.lineTo(width, 0); 517 path.lineTo(width, 0);
520 } 518 }
521 path.lineTo(width, height - radius - 1); 519 path.lineTo(width, height - radius - 1);
522 path.lineTo(width - radius - 1, height); 520 path.lineTo(width - radius - 1, height);
523 path.lineTo(radius + 1, height); 521 path.lineTo(radius + 1, height);
524 path.lineTo(0, height - radius - 1); 522 path.lineTo(0, height - radius - 1);
525 path.close(); 523 path.close();
526 } 524 }
527 SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1); 525 SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1);
528 526
529 SkRegion* rgn = new SkRegion; 527 SkRegion* rgn = new SkRegion;
530 if (!window_->IsFullscreen()) { 528 if (!window_->IsFullscreen()) {
531 if (caption_region_.Get()) 529 if (draggable_region_.Get())
532 rgn->op(*caption_region_.Get(), SkRegion::kUnion_Op); 530 rgn->op(*draggable_region_.Get(), SkRegion::kUnion_Op);
533 if (!window_->IsMaximized()) { 531 if (!window_->IsMaximized()) {
534 if (use_custom_frame_) 532 if (frameless_)
535 rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op); 533 rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op);
536 rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); 534 rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op);
537 rgn->op(width - kResizeInsideBoundsSize, 0, width, height, 535 rgn->op(width - kResizeInsideBoundsSize, 0, width, height,
538 SkRegion::kUnion_Op); 536 SkRegion::kUnion_Op);
539 rgn->op(0, height - kResizeInsideBoundsSize, width, height, 537 rgn->op(0, height - kResizeInsideBoundsSize, width, height,
540 SkRegion::kUnion_Op); 538 SkRegion::kUnion_Op);
541 } 539 }
542 } 540 }
543 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); 541 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn);
544 #endif 542 #endif
545 } 543 }
546 544
547 void ShellWindowViews::Layout() { 545 void ShellWindowViews::Layout() {
548 DCHECK(web_view_); 546 DCHECK(web_view_);
549 web_view_->SetBounds(0, 0, width(), height()); 547 web_view_->SetBounds(0, 0, width(), height());
550 OnViewWasResized(); 548 OnViewWasResized();
551 } 549 }
552 550
553 void ShellWindowViews::UpdateWindowTitle() { 551 void ShellWindowViews::UpdateWindowTitle() {
554 window_->UpdateWindowTitle(); 552 window_->UpdateWindowTitle();
555 } 553 }
556 554
555
jeremya 2012/08/07 01:00:17 nit: only 1 empty line here
jianli 2012/08/07 20:38:06 Done.
556 void ShellWindowViews::UpdateDraggableRegions(
557 const std::vector<content::DraggableRegion>& regions) {
558 // Draggable region is not supported for non-frameless window.
559 if (!frameless_)
560 return;
561
562 SkRegion* draggable_region = new SkRegion;
563
564 // By default, the whole window is draggable.
565 gfx::Rect bounds = GetBounds();
566 draggable_region->op(0, 0, bounds.right(), bounds.bottom(),
567 SkRegion::kUnion_Op);
568
569 // Exclude those desinated as non-draggable.
570 for (std::vector<content::DraggableRegion>::const_iterator iter =
571 regions.begin();
572 iter != regions.end(); ++iter) {
573 const content::DraggableRegion& region = *iter;
574 draggable_region->op(region.bounds.x(),
575 region.bounds.y(),
576 region.bounds.right(),
577 region.bounds.bottom(),
578 SkRegion::kDifference_Op);
579 }
580
581 draggable_region_.Set(draggable_region);
582 OnViewWasResized();
583 }
584
557 // static 585 // static
558 ShellWindow* ShellWindow::CreateImpl(Profile* profile, 586 ShellWindow* ShellWindow::CreateImpl(Profile* profile,
559 const extensions::Extension* extension, 587 const extensions::Extension* extension,
560 const GURL& url, 588 const GURL& url,
561 const ShellWindow::CreateParams& params) { 589 const ShellWindow::CreateParams& params) {
562 return new ShellWindowViews(profile, extension, url, params); 590 return new ShellWindowViews(profile, extension, url, params);
563 } 591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698