| OLD | NEW |
| 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/constrained_window_views.h" | 5 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/app/chrome_command_ids.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/themes/theme_service.h" | |
| 13 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 9 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 10 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 12 #include "chrome/browser/ui/views/constrained_window_frame_view.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 17 #include "chrome/common/chrome_constants.h" | |
| 18 #include "chrome/common/chrome_notification_types.h" | |
| 19 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_view.h" | 14 #include "content/public/browser/web_contents_view.h" |
| 21 #include "grit/chromium_strings.h" | |
| 22 #include "grit/generated_resources.h" | |
| 23 #include "grit/theme_resources.h" | |
| 24 #include "grit/theme_resources_standard.h" | |
| 25 #include "grit/ui_resources.h" | |
| 26 #include "net/base/net_util.h" | |
| 27 #include "ui/base/hit_test.h" | |
| 28 #include "ui/base/resource/resource_bundle.h" | |
| 29 #include "ui/gfx/canvas.h" | |
| 30 #include "ui/gfx/font.h" | |
| 31 #include "ui/gfx/path.h" | |
| 32 #include "ui/gfx/rect.h" | |
| 33 #include "ui/gfx/screen.h" | |
| 34 #include "ui/views/color_constants.h" | |
| 35 #include "ui/views/controls/button/image_button.h" | |
| 36 #include "ui/views/focus/focus_manager.h" | |
| 37 #include "ui/views/views_delegate.h" | |
| 38 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 39 #include "ui/views/window/client_view.h" | 16 #include "ui/views/widget/widget_delegate.h" |
| 40 #include "ui/views/window/frame_background.h" | |
| 41 #include "ui/views/window/non_client_view.h" | |
| 42 #include "ui/views/window/window_resources.h" | |
| 43 #include "ui/views/window/window_shape.h" | |
| 44 | |
| 45 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 46 #include "ui/views/widget/native_widget_win.h" | |
| 47 #endif | |
| 48 | |
| 49 #if defined(USE_ASH) | |
| 50 #include "ash/ash_switches.h" | |
| 51 #include "ash/shell.h" | |
| 52 #include "ash/wm/custom_frame_view_ash.h" | |
| 53 #include "ash/wm/visibility_controller.h" | |
| 54 #include "base/command_line.h" | |
| 55 #include "ui/aura/window.h" | |
| 56 #endif | |
| 57 | |
| 58 using base::TimeDelta; | |
| 59 | |
| 60 namespace views { | |
| 61 class ClientView; | |
| 62 } | |
| 63 | |
| 64 // An enumeration of image resources used by this window. | |
| 65 enum { | |
| 66 FRAME_PART_IMAGE_FIRST = 0, // Must be first. | |
| 67 | |
| 68 // Window Frame Border. | |
| 69 FRAME_BOTTOM_EDGE, | |
| 70 FRAME_BOTTOM_LEFT_CORNER, | |
| 71 FRAME_BOTTOM_RIGHT_CORNER, | |
| 72 FRAME_LEFT_EDGE, | |
| 73 FRAME_RIGHT_EDGE, | |
| 74 FRAME_TOP_EDGE, | |
| 75 FRAME_TOP_LEFT_CORNER, | |
| 76 FRAME_TOP_RIGHT_CORNER, | |
| 77 | |
| 78 FRAME_PART_IMAGE_COUNT // Must be last. | |
| 79 }; | |
| 80 | |
| 81 static const int kXPFramePartIDs[] = { | |
| 82 0, | |
| 83 IDR_WINDOW_BOTTOM_CENTER, IDR_WINDOW_BOTTOM_LEFT_CORNER, | |
| 84 IDR_WINDOW_BOTTOM_RIGHT_CORNER, IDR_WINDOW_LEFT_SIDE, | |
| 85 IDR_WINDOW_RIGHT_SIDE, IDR_WINDOW_TOP_CENTER, | |
| 86 IDR_WINDOW_TOP_LEFT_CORNER, IDR_WINDOW_TOP_RIGHT_CORNER, | |
| 87 0 }; | |
| 88 static const int kVistaFramePartIDs[] = { | |
| 89 0, | |
| 90 IDR_CONSTRAINED_BOTTOM_CENTER_V, IDR_CONSTRAINED_BOTTOM_LEFT_CORNER_V, | |
| 91 IDR_CONSTRAINED_BOTTOM_RIGHT_CORNER_V, IDR_CONSTRAINED_LEFT_SIDE_V, | |
| 92 IDR_CONSTRAINED_RIGHT_SIDE_V, IDR_CONSTRAINED_TOP_CENTER_V, | |
| 93 IDR_CONSTRAINED_TOP_LEFT_CORNER_V, IDR_CONSTRAINED_TOP_RIGHT_CORNER_V, | |
| 94 0 }; | |
| 95 | |
| 96 class XPWindowResources : public views::WindowResources { | |
| 97 public: | |
| 98 XPWindowResources() { | |
| 99 InitClass(); | |
| 100 } | |
| 101 virtual ~XPWindowResources() {} | |
| 102 | |
| 103 virtual gfx::ImageSkia* GetPartImage(views::FramePartImage part_id) const { | |
| 104 return images_[part_id]; | |
| 105 } | |
| 106 | |
| 107 private: | |
| 108 static void InitClass() { | |
| 109 static bool initialized = false; | |
| 110 if (!initialized) { | |
| 111 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 112 for (int i = 0; i < FRAME_PART_IMAGE_COUNT; ++i) { | |
| 113 int id = kXPFramePartIDs[i]; | |
| 114 if (id != 0) | |
| 115 images_[i] = rb.GetImageSkiaNamed(id); | |
| 116 } | |
| 117 initialized = true; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 static gfx::ImageSkia* images_[FRAME_PART_IMAGE_COUNT]; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(XPWindowResources); | |
| 124 }; | |
| 125 | |
| 126 class VistaWindowResources : public views::WindowResources { | |
| 127 public: | |
| 128 VistaWindowResources() { | |
| 129 InitClass(); | |
| 130 } | |
| 131 virtual ~VistaWindowResources() {} | |
| 132 | |
| 133 virtual gfx::ImageSkia* GetPartImage(views::FramePartImage part_id) const { | |
| 134 return images_[part_id]; | |
| 135 } | |
| 136 | |
| 137 private: | |
| 138 static void InitClass() { | |
| 139 static bool initialized = false; | |
| 140 if (!initialized) { | |
| 141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 142 for (int i = 0; i < FRAME_PART_IMAGE_COUNT; ++i) { | |
| 143 int id = kVistaFramePartIDs[i]; | |
| 144 if (id != 0) | |
| 145 images_[i] = rb.GetImageSkiaNamed(id); | |
| 146 } | |
| 147 initialized = true; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 static gfx::ImageSkia* images_[FRAME_PART_IMAGE_COUNT]; | |
| 152 | |
| 153 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources); | |
| 154 }; | |
| 155 | |
| 156 gfx::ImageSkia* XPWindowResources::images_[]; | |
| 157 gfx::ImageSkia* VistaWindowResources::images_[]; | |
| 158 | |
| 159 //////////////////////////////////////////////////////////////////////////////// | |
| 160 // ConstrainedWindowFrameView | |
| 161 | |
| 162 class ConstrainedWindowFrameView : public views::NonClientFrameView, | |
| 163 public views::ButtonListener { | |
| 164 public: | |
| 165 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container); | |
| 166 virtual ~ConstrainedWindowFrameView(); | |
| 167 | |
| 168 void UpdateWindowTitle(); | |
| 169 | |
| 170 // Overridden from views::NonClientFrameView: | |
| 171 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; | |
| 172 virtual gfx::Rect GetWindowBoundsForClientBounds( | |
| 173 const gfx::Rect& client_bounds) const OVERRIDE; | |
| 174 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; | |
| 175 virtual void GetWindowMask(const gfx::Size& size, | |
| 176 gfx::Path* window_mask) OVERRIDE; | |
| 177 virtual void ResetWindowControls() OVERRIDE {} | |
| 178 virtual void UpdateWindowIcon() OVERRIDE {} | |
| 179 | |
| 180 // Overridden from views::View: | |
| 181 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
| 182 virtual void Layout() OVERRIDE; | |
| 183 virtual void OnThemeChanged() OVERRIDE; | |
| 184 | |
| 185 // Overridden from views::ButtonListener: | |
| 186 virtual void ButtonPressed(views::Button* sender, | |
| 187 const views::Event& event) OVERRIDE; | |
| 188 | |
| 189 private: | |
| 190 // Returns the thickness of the entire nonclient left, right, and bottom | |
| 191 // borders, including both the window frame and any client edge. | |
| 192 int NonClientBorderThickness() const; | |
| 193 | |
| 194 // Returns the height of the entire nonclient top border, including the window | |
| 195 // frame, any title area, and any connected client edge. | |
| 196 int NonClientTopBorderHeight() const; | |
| 197 | |
| 198 // Returns the thickness of the nonclient portion of the 3D edge along the | |
| 199 // bottom of the titlebar. | |
| 200 int TitlebarBottomThickness() const; | |
| 201 | |
| 202 // Returns what the size of the titlebar icon would be if there was one. | |
| 203 int IconSize() const; | |
| 204 | |
| 205 // Returns what the titlebar icon's bounds would be if there was one. | |
| 206 gfx::Rect IconBounds() const; | |
| 207 | |
| 208 // Paints different parts of the window to the incoming canvas. | |
| 209 void PaintFrameBorder(gfx::Canvas* canvas); | |
| 210 void PaintTitleBar(gfx::Canvas* canvas); | |
| 211 void PaintClientEdge(gfx::Canvas* canvas); | |
| 212 | |
| 213 // Layout various sub-components of this view. | |
| 214 void LayoutWindowControls(); | |
| 215 void LayoutTitleBar(); | |
| 216 | |
| 217 // Returns the bounds of the client area for the specified view size. | |
| 218 gfx::Rect CalculateClientAreaBounds(int width, int height) const; | |
| 219 | |
| 220 SkColor GetTitleColor() const { | |
| 221 return container_->owner()->profile()->IsOffTheRecord() | |
| 222 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 223 || !views::NativeWidgetWin::IsAeroGlassEnabled() | |
| 224 #endif | |
| 225 ? SK_ColorWHITE : SK_ColorBLACK; | |
| 226 } | |
| 227 | |
| 228 // Loads the appropriate set of WindowResources for the frame view. | |
| 229 void InitWindowResources(); | |
| 230 | |
| 231 ConstrainedWindowViews* container_; | |
| 232 | |
| 233 scoped_ptr<views::WindowResources> resources_; | |
| 234 | |
| 235 gfx::Rect title_bounds_; | |
| 236 | |
| 237 views::ImageButton* close_button_; | |
| 238 | |
| 239 // The bounds of the ClientView. | |
| 240 gfx::Rect client_view_bounds_; | |
| 241 | |
| 242 // Background painter for the frame. | |
| 243 scoped_ptr<views::FrameBackground> frame_background_; | |
| 244 | |
| 245 static void InitClass(); | |
| 246 | |
| 247 // The font to be used to render the titlebar text. | |
| 248 static const gfx::Font* title_font_; | |
| 249 | |
| 250 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameView); | |
| 251 }; | |
| 252 | |
| 253 const gfx::Font* ConstrainedWindowFrameView::title_font_ = NULL; | |
| 254 | |
| 255 namespace { | |
| 256 // The frame border is only visible in restored mode and is hardcoded to 4 px on | |
| 257 // each side regardless of the system window border size. | |
| 258 const int kFrameBorderThickness = 4; | |
| 259 // Various edges of the frame border have a 1 px shadow along their edges; in a | |
| 260 // few cases we shift elements based on this amount for visual appeal. | |
| 261 const int kFrameShadowThickness = 1; | |
| 262 // In the window corners, the resize areas don't actually expand bigger, but the | |
| 263 // 16 px at the end of each edge triggers diagonal resizing. | |
| 264 const int kResizeAreaCornerSize = 16; | |
| 265 // The titlebar never shrinks too short to show the caption button plus some | |
| 266 // padding below it. | |
| 267 const int kCaptionButtonHeightWithPadding = 19; | |
| 268 // The titlebar has a 2 px 3D edge along the top and bottom. | |
| 269 const int kTitlebarTopAndBottomEdgeThickness = 2; | |
| 270 // The icon would never shrink below 16 px on a side, if there was one. | |
| 271 const int kIconMinimumSize = 16; | |
| 272 // The title text starts 2 px from the right edge of the left frame border. | |
| 273 const int kTitleLeftSpacing = 2; | |
| 274 // There is a 5 px gap between the title text and the caption buttons. | |
| 275 const int kTitleCaptionSpacing = 5; | |
| 276 | |
| 277 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); | |
| 278 | |
| 279 } // namespace | |
| 280 | |
| 281 //////////////////////////////////////////////////////////////////////////////// | |
| 282 // ConstrainedWindowFrameView, public: | |
| 283 | |
| 284 ConstrainedWindowFrameView::ConstrainedWindowFrameView( | |
| 285 ConstrainedWindowViews* container) | |
| 286 : NonClientFrameView(), | |
| 287 container_(container), | |
| 288 close_button_(new views::ImageButton(this)), | |
| 289 frame_background_(new views::FrameBackground()) { | |
| 290 InitClass(); | |
| 291 InitWindowResources(); | |
| 292 | |
| 293 // Constrained windows always use the custom frame - they just have a | |
| 294 // different set of images. | |
| 295 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | |
| 296 | |
| 297 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 298 close_button_->SetImage(views::CustomButton::BS_NORMAL, | |
| 299 rb.GetImageSkiaNamed(IDR_CLOSE_SA)); | |
| 300 close_button_->SetImage(views::CustomButton::BS_HOT, | |
| 301 rb.GetImageSkiaNamed(IDR_CLOSE_SA_H)); | |
| 302 close_button_->SetImage(views::CustomButton::BS_PUSHED, | |
| 303 rb.GetImageSkiaNamed(IDR_CLOSE_SA_P)); | |
| 304 close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
| 305 views::ImageButton::ALIGN_MIDDLE); | |
| 306 AddChildView(close_button_); | |
| 307 } | |
| 308 | |
| 309 ConstrainedWindowFrameView::~ConstrainedWindowFrameView() { | |
| 310 } | |
| 311 | |
| 312 void ConstrainedWindowFrameView::UpdateWindowTitle() { | |
| 313 SchedulePaintInRect(title_bounds_); | |
| 314 } | |
| 315 | |
| 316 //////////////////////////////////////////////////////////////////////////////// | |
| 317 // ConstrainedWindowFrameView, views::NonClientFrameView implementation: | |
| 318 | |
| 319 gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const { | |
| 320 return client_view_bounds_; | |
| 321 } | |
| 322 | |
| 323 gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds( | |
| 324 const gfx::Rect& client_bounds) const { | |
| 325 int top_height = NonClientTopBorderHeight(); | |
| 326 int border_thickness = NonClientBorderThickness(); | |
| 327 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), | |
| 328 std::max(0, client_bounds.y() - top_height), | |
| 329 client_bounds.width() + (2 * border_thickness), | |
| 330 client_bounds.height() + top_height + border_thickness); | |
| 331 } | |
| 332 | |
| 333 int ConstrainedWindowFrameView::NonClientHitTest(const gfx::Point& point) { | |
| 334 if (!bounds().Contains(point)) | |
| 335 return HTNOWHERE; | |
| 336 | |
| 337 int frame_component = | |
| 338 container_->client_view()->NonClientHitTest(point); | |
| 339 | |
| 340 // See if we're in the sysmenu region. (We check the ClientView first to be | |
| 341 // consistent with OpaqueBrowserFrameView; it's not really necessary here.) | |
| 342 gfx::Rect sysmenu_rect(IconBounds()); | |
| 343 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); | |
| 344 if (sysmenu_rect.Contains(point)) | |
| 345 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; | |
| 346 | |
| 347 if (frame_component != HTNOWHERE) | |
| 348 return frame_component; | |
| 349 | |
| 350 // Then see if the point is within any of the window controls. | |
| 351 if (close_button_->GetMirroredBounds().Contains(point)) | |
| 352 return HTCLOSE; | |
| 353 | |
| 354 int window_component = GetHTComponentForFrame(point, kFrameBorderThickness, | |
| 355 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, | |
| 356 container_->widget_delegate()->CanResize()); | |
| 357 // Fall back to the caption if no other component matches. | |
| 358 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | |
| 359 } | |
| 360 | |
| 361 void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size, | |
| 362 gfx::Path* window_mask) { | |
| 363 DCHECK(window_mask); | |
| 364 views::GetDefaultWindowMask(size, window_mask); | |
| 365 } | |
| 366 | |
| 367 //////////////////////////////////////////////////////////////////////////////// | |
| 368 // ConstrainedWindowFrameView, views::View implementation: | |
| 369 | |
| 370 void ConstrainedWindowFrameView::OnPaint(gfx::Canvas* canvas) { | |
| 371 PaintFrameBorder(canvas); | |
| 372 PaintTitleBar(canvas); | |
| 373 PaintClientEdge(canvas); | |
| 374 } | |
| 375 | |
| 376 void ConstrainedWindowFrameView::Layout() { | |
| 377 LayoutWindowControls(); | |
| 378 LayoutTitleBar(); | |
| 379 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); | |
| 380 } | |
| 381 | |
| 382 void ConstrainedWindowFrameView::OnThemeChanged() { | |
| 383 InitWindowResources(); | |
| 384 } | |
| 385 | |
| 386 //////////////////////////////////////////////////////////////////////////////// | |
| 387 // ConstrainedWindowFrameView, views::ButtonListener implementation: | |
| 388 | |
| 389 void ConstrainedWindowFrameView::ButtonPressed( | |
| 390 views::Button* sender, const views::Event& event) { | |
| 391 if (sender == close_button_) | |
| 392 container_->CloseConstrainedWindow(); | |
| 393 } | |
| 394 | |
| 395 //////////////////////////////////////////////////////////////////////////////// | |
| 396 // ConstrainedWindowFrameView, private: | |
| 397 | |
| 398 int ConstrainedWindowFrameView::NonClientBorderThickness() const { | |
| 399 return kFrameBorderThickness + kClientEdgeThickness; | |
| 400 } | |
| 401 | |
| 402 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const { | |
| 403 return std::max(kFrameBorderThickness + IconSize(), | |
| 404 kFrameShadowThickness + kCaptionButtonHeightWithPadding) + | |
| 405 TitlebarBottomThickness(); | |
| 406 } | |
| 407 | |
| 408 int ConstrainedWindowFrameView::TitlebarBottomThickness() const { | |
| 409 return kTitlebarTopAndBottomEdgeThickness + kClientEdgeThickness; | |
| 410 } | |
| 411 | |
| 412 int ConstrainedWindowFrameView::IconSize() const { | |
| 413 #if defined(OS_WIN) | |
| 414 // This metric scales up if either the titlebar height or the titlebar font | |
| 415 // size are increased. | |
| 416 return GetSystemMetrics(SM_CYSMICON); | |
| 417 #else | |
| 418 return std::max(title_font_->GetHeight(), kIconMinimumSize); | |
| 419 #endif | |
| 420 } | |
| 421 | |
| 422 gfx::Rect ConstrainedWindowFrameView::IconBounds() const { | |
| 423 int size = IconSize(); | |
| 424 // Our frame border has a different "3D look" than Windows'. Theirs has a | |
| 425 // more complex gradient on the top that they push their icon/title below; | |
| 426 // then the maximized window cuts this off and the icon/title are centered | |
| 427 // in the remaining space. Because the apparent shape of our border is | |
| 428 // simpler, using the same positioning makes things look slightly uncentered | |
| 429 // with restored windows, so instead of calculating the remaining space from | |
| 430 // below the frame border, we calculate from below the 3D edge. | |
| 431 int unavailable_px_at_top = kTitlebarTopAndBottomEdgeThickness; | |
| 432 // When the icon is shorter than the minimum space we reserve for the caption | |
| 433 // button, we vertically center it. We want to bias rounding to put extra | |
| 434 // space above the icon, since the 3D edge + client edge below looks (to the | |
| 435 // eye) more like additional space than does the 3D edge above; hence the +1. | |
| 436 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - | |
| 437 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; | |
| 438 return gfx::Rect(kFrameBorderThickness + kTitleLeftSpacing, y, size, size); | |
| 439 } | |
| 440 | |
| 441 void ConstrainedWindowFrameView::PaintFrameBorder(gfx::Canvas* canvas) { | |
| 442 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 443 frame_background_->set_frame_color(ThemeService::GetDefaultColor( | |
| 444 ThemeService::COLOR_FRAME)); | |
| 445 gfx::ImageSkia* theme_frame = rb.GetImageSkiaNamed(IDR_THEME_FRAME); | |
| 446 frame_background_->set_theme_image(theme_frame); | |
| 447 frame_background_->set_theme_overlay_image(NULL); | |
| 448 frame_background_->set_top_area_height(theme_frame->height()); | |
| 449 | |
| 450 frame_background_->SetCornerImages( | |
| 451 resources_->GetPartImage(FRAME_TOP_LEFT_CORNER), | |
| 452 resources_->GetPartImage(FRAME_TOP_RIGHT_CORNER), | |
| 453 resources_->GetPartImage(FRAME_BOTTOM_LEFT_CORNER), | |
| 454 resources_->GetPartImage(FRAME_BOTTOM_RIGHT_CORNER)); | |
| 455 frame_background_->SetSideImages( | |
| 456 resources_->GetPartImage(FRAME_LEFT_EDGE), | |
| 457 resources_->GetPartImage(FRAME_TOP_EDGE), | |
| 458 resources_->GetPartImage(FRAME_RIGHT_EDGE), | |
| 459 resources_->GetPartImage(FRAME_BOTTOM_EDGE)); | |
| 460 frame_background_->PaintRestored(canvas, this); | |
| 461 } | |
| 462 | |
| 463 void ConstrainedWindowFrameView::PaintTitleBar(gfx::Canvas* canvas) { | |
| 464 canvas->DrawStringInt( | |
| 465 container_->widget_delegate()->GetWindowTitle(), | |
| 466 *title_font_, GetTitleColor(), GetMirroredXForRect(title_bounds_), | |
| 467 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); | |
| 468 } | |
| 469 | |
| 470 void ConstrainedWindowFrameView::PaintClientEdge(gfx::Canvas* canvas) { | |
| 471 gfx::Rect client_edge_bounds(CalculateClientAreaBounds(width(), height())); | |
| 472 client_edge_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness); | |
| 473 gfx::Rect frame_shadow_bounds(client_edge_bounds); | |
| 474 frame_shadow_bounds.Inset(-kFrameShadowThickness, -kFrameShadowThickness); | |
| 475 | |
| 476 canvas->FillRect(frame_shadow_bounds, kContentsBorderShadow); | |
| 477 canvas->FillRect(client_edge_bounds, views::kClientEdgeColor); | |
| 478 } | |
| 479 | |
| 480 void ConstrainedWindowFrameView::LayoutWindowControls() { | |
| 481 gfx::Size close_button_size = close_button_->GetPreferredSize(); | |
| 482 close_button_->SetBounds( | |
| 483 width() - kFrameBorderThickness - close_button_size.width(), | |
| 484 kFrameShadowThickness, close_button_size.width(), | |
| 485 close_button_size.height()); | |
| 486 } | |
| 487 | |
| 488 void ConstrainedWindowFrameView::LayoutTitleBar() { | |
| 489 // The window title is based on the calculated icon position, even though' | |
| 490 // there is no icon in constrained windows. | |
| 491 gfx::Rect icon_bounds(IconBounds()); | |
| 492 int title_x = icon_bounds.x(); | |
| 493 int title_height = title_font_->GetHeight(); | |
| 494 // We bias the title position so that when the difference between the icon and | |
| 495 // title heights is odd, the extra pixel of the title is above the vertical | |
| 496 // midline rather than below. This compensates for how the icon is already | |
| 497 // biased downwards (see IconBounds()) and helps prevent descenders on the | |
| 498 // title from overlapping the 3D edge at the bottom of the titlebar. | |
| 499 title_bounds_.SetRect(title_x, | |
| 500 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), | |
| 501 std::max(0, close_button_->x() - kTitleCaptionSpacing - title_x), | |
| 502 title_height); | |
| 503 } | |
| 504 | |
| 505 gfx::Rect ConstrainedWindowFrameView::CalculateClientAreaBounds( | |
| 506 int width, | |
| 507 int height) const { | |
| 508 int top_height = NonClientTopBorderHeight(); | |
| 509 int border_thickness = NonClientBorderThickness(); | |
| 510 return gfx::Rect(border_thickness, top_height, | |
| 511 std::max(0, width - (2 * border_thickness)), | |
| 512 std::max(0, height - top_height - border_thickness)); | |
| 513 } | |
| 514 | |
| 515 void ConstrainedWindowFrameView::InitWindowResources() { | |
| 516 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 517 resources_.reset(views::NativeWidgetWin::IsAeroGlassEnabled() ? | |
| 518 static_cast<views::WindowResources*>(new VistaWindowResources) : | |
| 519 new XPWindowResources); | |
| 520 #else | |
| 521 // TODO(oshima): Use aura frame decoration. | |
| 522 resources_.reset(new XPWindowResources); | |
| 523 #endif | |
| 524 } | |
| 525 | |
| 526 // static | |
| 527 void ConstrainedWindowFrameView::InitClass() { | |
| 528 static bool initialized = false; | |
| 529 if (!initialized) { | |
| 530 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 531 title_font_ = new gfx::Font(views::NativeWidgetWin::GetWindowTitleFont()); | |
| 532 #else | |
| 533 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 534 title_font_ = &rb.GetFont(ui::ResourceBundle::MediumFont); | |
| 535 #endif | |
| 536 initialized = true; | |
| 537 } | |
| 538 } | |
| 539 | |
| 540 #if defined(USE_ASH) | |
| 541 // Ash has its own window frames, but we need the special close semantics for | |
| 542 // constrained windows. | |
| 543 class ConstrainedWindowFrameViewAsh : public ash::CustomFrameViewAsh { | |
| 544 public: | |
| 545 explicit ConstrainedWindowFrameViewAsh() | |
| 546 : ash::CustomFrameViewAsh(), | |
| 547 container_(NULL) { | |
| 548 } | |
| 549 | |
| 550 void Init(ConstrainedWindowViews* container) { | |
| 551 container_ = container; | |
| 552 ash::CustomFrameViewAsh::Init(container); | |
| 553 // Always use "active" look. | |
| 554 SetInactiveRenderingDisabled(true); | |
| 555 } | |
| 556 | |
| 557 // views::ButtonListener overrides: | |
| 558 virtual void ButtonPressed(views::Button* sender, | |
| 559 const views::Event& event) OVERRIDE { | |
| 560 if (sender == close_button()) | |
| 561 container_->CloseConstrainedWindow(); | |
| 562 } | |
| 563 | |
| 564 private: | |
| 565 ConstrainedWindowViews* container_; // not owned | |
| 566 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); | |
| 567 }; | |
| 568 #endif // defined(USE_ASH) | |
| 569 | 17 |
| 570 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 571 // ConstrainedWindowViews, public: | 19 // ConstrainedWindowViews, public: |
| 572 | 20 |
| 573 ConstrainedWindowViews::ConstrainedWindowViews( | 21 ConstrainedWindowViews::ConstrainedWindowViews( |
| 574 TabContents* tab_contents, | 22 TabContents* tab_contents, |
| 575 views::WidgetDelegate* widget_delegate) | 23 views::WidgetDelegate* widget_delegate) |
| 576 : tab_contents_(tab_contents), | 24 : tab_contents_(tab_contents), |
| 577 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( | 25 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( |
| 578 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { | 26 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { |
| 27 // Using TYPE_WINDOW_FRAMELESS here would NOT give us what we want. |
| 28 // Doing so results in a popup window. |
| 579 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 29 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 580 params.delegate = widget_delegate; | 30 params.delegate = widget_delegate; |
| 581 params.native_widget = native_constrained_window_->AsNativeWidget(); | 31 params.native_widget = native_constrained_window_->AsNativeWidget(); |
| 582 params.child = true; | 32 params.child = true; |
| 583 params.parent = tab_contents->web_contents()->GetNativeView(); | 33 params.parent = tab_contents->web_contents()->GetNativeView(); |
| 584 #if defined(USE_ASH) | 34 params.has_dropshadow = true; |
| 585 // Ash window headers can be transparent. | |
| 586 params.transparent = true; | |
| 587 ash::SetChildWindowVisibilityChangesAnimated(params.parent); | |
| 588 #endif | |
| 589 Init(params); | 35 Init(params); |
| 590 | 36 |
| 591 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this); | 37 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this); |
| 592 } | 38 } |
| 593 | 39 |
| 594 ConstrainedWindowViews::~ConstrainedWindowViews() { | 40 ConstrainedWindowViews::~ConstrainedWindowViews() { |
| 595 } | 41 } |
| 596 | 42 |
| 597 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 598 // ConstrainedWindowViews, ConstrainedWindow implementation: | 44 // ConstrainedWindowViews, ConstrainedWindow implementation: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 613 | 59 |
| 614 void ConstrainedWindowViews::FocusConstrainedWindow() { | 60 void ConstrainedWindowViews::FocusConstrainedWindow() { |
| 615 ConstrainedWindowTabHelper* helper = | 61 ConstrainedWindowTabHelper* helper = |
| 616 tab_contents_->constrained_window_tab_helper(); | 62 tab_contents_->constrained_window_tab_helper(); |
| 617 if ((!helper->delegate() || | 63 if ((!helper->delegate() || |
| 618 helper->delegate()->ShouldFocusConstrainedWindow()) && | 64 helper->delegate()->ShouldFocusConstrainedWindow()) && |
| 619 widget_delegate() && | 65 widget_delegate() && |
| 620 widget_delegate()->GetInitiallyFocusedView()) { | 66 widget_delegate()->GetInitiallyFocusedView()) { |
| 621 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); | 67 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
| 622 } | 68 } |
| 623 #if defined(USE_ASH) | |
| 624 GetNativeView()->Focus(); | |
| 625 #endif | |
| 626 } | 69 } |
| 627 | 70 |
| 628 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() { | 71 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() { |
| 629 return Widget::GetNativeWindow(); | 72 return Widget::GetNativeWindow(); |
| 630 } | 73 } |
| 631 | 74 |
| 632 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
| 633 // ConstrainedWindowViews, views::Widget overrides: | |
| 634 | |
| 635 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { | |
| 636 #if defined(USE_ASH) | |
| 637 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 638 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames)) | |
| 639 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); | |
| 640 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; | |
| 641 frame->Init(this); | |
| 642 return frame; | |
| 643 #endif | |
| 644 return new ConstrainedWindowFrameView(this); | |
| 645 } | |
| 646 | |
| 647 //////////////////////////////////////////////////////////////////////////////// | |
| 648 // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: | 76 // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: |
| 649 | 77 |
| 650 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { | 78 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { |
| 651 tab_contents_->constrained_window_tab_helper()->WillClose(this); | 79 tab_contents_->constrained_window_tab_helper()->WillClose(this); |
| 652 } | 80 } |
| 653 | 81 |
| 654 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { | 82 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { |
| 655 Activate(); | 83 Activate(); |
| 656 } | 84 } |
| 657 | 85 |
| 658 views::internal::NativeWidgetDelegate* | 86 views::internal::NativeWidgetDelegate* |
| 659 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 87 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 660 return this; | 88 return this; |
| 661 } | 89 } |
| 90 |
| 91 //////////////////////////////////////////////////////////////////////////////// |
| 92 // ConstrainedWindowViews, views::Widget overrides: |
| 93 |
| 94 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { |
| 95 return new ConstrainedWindowFrameView(this); |
| 96 } |
| OLD | NEW |