| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/ui/views/shell_window_frame_view.h" | 5 #include "apps/ui/views/app_window_frame_view.h" |
| 6 | 6 |
| 7 #include "apps/ui/native_app_window.h" | 7 #include "apps/ui/native_app_window.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "extensions/common/draggable_region.h" | 9 #include "extensions/common/draggable_region.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 11 #include "grit/ui_strings.h" // Accessibility names | 11 #include "grit/ui_strings.h" // Accessibility names |
| 12 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
| 13 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 // Height of the chrome-style caption, in pixels. | 31 // Height of the chrome-style caption, in pixels. |
| 32 const int kCaptionHeight = 25; | 32 const int kCaptionHeight = 25; |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace apps { | 35 namespace apps { |
| 36 | 36 |
| 37 const char ShellWindowFrameView::kViewClassName[] = | 37 const char AppWindowFrameView::kViewClassName[] = |
| 38 "browser/ui/views/extensions/ShellWindowFrameView"; | 38 "browser/ui/views/extensions/AppWindowFrameView"; |
| 39 | 39 |
| 40 ShellWindowFrameView::ShellWindowFrameView(NativeAppWindow* window) | 40 AppWindowFrameView::AppWindowFrameView(NativeAppWindow* window) |
| 41 : window_(window), | 41 : window_(window), |
| 42 frame_(NULL), | 42 frame_(NULL), |
| 43 close_button_(NULL), | 43 close_button_(NULL), |
| 44 maximize_button_(NULL), | 44 maximize_button_(NULL), |
| 45 restore_button_(NULL), | 45 restore_button_(NULL), |
| 46 minimize_button_(NULL), | 46 minimize_button_(NULL), |
| 47 resize_inside_bounds_size_(0), | 47 resize_inside_bounds_size_(0), |
| 48 resize_outside_bounds_size_(0), | 48 resize_outside_bounds_size_(0), |
| 49 resize_area_corner_size_(0) { | 49 resize_area_corner_size_(0) {} |
| 50 } | |
| 51 | 50 |
| 52 ShellWindowFrameView::~ShellWindowFrameView() { | 51 AppWindowFrameView::~AppWindowFrameView() {} |
| 53 } | |
| 54 | 52 |
| 55 void ShellWindowFrameView::Init(views::Widget* frame, | 53 void AppWindowFrameView::Init(views::Widget* frame, |
| 56 int resize_inside_bounds_size, | 54 int resize_inside_bounds_size, |
| 57 int resize_outside_bounds_size, | 55 int resize_outside_bounds_size, |
| 58 int resize_outside_scale_for_touch, | 56 int resize_outside_scale_for_touch, |
| 59 int resize_area_corner_size) { | 57 int resize_area_corner_size) { |
| 60 frame_ = frame; | 58 frame_ = frame; |
| 61 resize_inside_bounds_size_ = resize_inside_bounds_size; | 59 resize_inside_bounds_size_ = resize_inside_bounds_size; |
| 62 resize_outside_bounds_size_ = resize_outside_bounds_size; | 60 resize_outside_bounds_size_ = resize_outside_bounds_size; |
| 63 resize_area_corner_size_ = resize_area_corner_size; | 61 resize_area_corner_size_ = resize_area_corner_size; |
| 64 | 62 |
| 65 if (!window_->IsFrameless()) { | 63 if (!window_->IsFrameless()) { |
| 66 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 64 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 67 close_button_ = new views::ImageButton(this); | 65 close_button_ = new views::ImageButton(this); |
| 68 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 66 close_button_->SetImage( |
| 67 views::CustomButton::STATE_NORMAL, |
| 69 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 68 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
| 70 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 69 close_button_->SetImage( |
| 70 views::CustomButton::STATE_HOVERED, |
| 71 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); | 71 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); |
| 72 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 72 close_button_->SetImage( |
| 73 views::CustomButton::STATE_PRESSED, |
| 73 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); | 74 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); |
| 74 close_button_->SetAccessibleName( | 75 close_button_->SetAccessibleName( |
| 75 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 76 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
| 76 AddChildView(close_button_); | 77 AddChildView(close_button_); |
| 77 maximize_button_ = new views::ImageButton(this); | 78 maximize_button_ = new views::ImageButton(this); |
| 78 maximize_button_->SetImage(views::CustomButton::STATE_NORMAL, | 79 maximize_button_->SetImage( |
| 80 views::CustomButton::STATE_NORMAL, |
| 79 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE).ToImageSkia()); | 81 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE).ToImageSkia()); |
| 80 maximize_button_->SetImage(views::CustomButton::STATE_HOVERED, | 82 maximize_button_->SetImage( |
| 83 views::CustomButton::STATE_HOVERED, |
| 81 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia()); | 84 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia()); |
| 82 maximize_button_->SetImage(views::CustomButton::STATE_PRESSED, | 85 maximize_button_->SetImage( |
| 86 views::CustomButton::STATE_PRESSED, |
| 83 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_P).ToImageSkia()); | 87 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_P).ToImageSkia()); |
| 84 maximize_button_->SetImage(views::CustomButton::STATE_DISABLED, | 88 maximize_button_->SetImage( |
| 89 views::CustomButton::STATE_DISABLED, |
| 85 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_D).ToImageSkia()); | 90 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_D).ToImageSkia()); |
| 86 maximize_button_->SetAccessibleName( | 91 maximize_button_->SetAccessibleName( |
| 87 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); | 92 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); |
| 88 AddChildView(maximize_button_); | 93 AddChildView(maximize_button_); |
| 89 restore_button_ = new views::ImageButton(this); | 94 restore_button_ = new views::ImageButton(this); |
| 90 restore_button_->SetImage(views::CustomButton::STATE_NORMAL, | 95 restore_button_->SetImage( |
| 96 views::CustomButton::STATE_NORMAL, |
| 91 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE).ToImageSkia()); | 97 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE).ToImageSkia()); |
| 92 restore_button_->SetImage(views::CustomButton::STATE_HOVERED, | 98 restore_button_->SetImage( |
| 99 views::CustomButton::STATE_HOVERED, |
| 93 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia()); | 100 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia()); |
| 94 restore_button_->SetImage(views::CustomButton::STATE_PRESSED, | 101 restore_button_->SetImage( |
| 102 views::CustomButton::STATE_PRESSED, |
| 95 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_P).ToImageSkia()); | 103 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_P).ToImageSkia()); |
| 96 restore_button_->SetAccessibleName( | 104 restore_button_->SetAccessibleName( |
| 97 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); | 105 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); |
| 98 AddChildView(restore_button_); | 106 AddChildView(restore_button_); |
| 99 minimize_button_ = new views::ImageButton(this); | 107 minimize_button_ = new views::ImageButton(this); |
| 100 minimize_button_->SetImage(views::CustomButton::STATE_NORMAL, | 108 minimize_button_->SetImage( |
| 109 views::CustomButton::STATE_NORMAL, |
| 101 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE).ToImageSkia()); | 110 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE).ToImageSkia()); |
| 102 minimize_button_->SetImage(views::CustomButton::STATE_HOVERED, | 111 minimize_button_->SetImage( |
| 112 views::CustomButton::STATE_HOVERED, |
| 103 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); | 113 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); |
| 104 minimize_button_->SetImage(views::CustomButton::STATE_PRESSED, | 114 minimize_button_->SetImage( |
| 115 views::CustomButton::STATE_PRESSED, |
| 105 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); | 116 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); |
| 106 minimize_button_->SetAccessibleName( | 117 minimize_button_->SetAccessibleName( |
| 107 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 118 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
| 108 AddChildView(minimize_button_); | 119 AddChildView(minimize_button_); |
| 109 } | 120 } |
| 110 | 121 |
| 111 #if defined(USE_AURA) | 122 #if defined(USE_AURA) |
| 112 aura::Window* window = frame->GetNativeWindow(); | 123 aura::Window* window = frame->GetNativeWindow(); |
| 113 // Ensure we get resize cursors just inside our bounds as well. | 124 // Ensure we get resize cursors just inside our bounds as well. |
| 114 // TODO(jeremya): do we need to update these when in fullscreen/maximized? | 125 // TODO(jeremya): do we need to update these when in fullscreen/maximized? |
| 115 window->set_hit_test_bounds_override_inner( | 126 window->set_hit_test_bounds_override_inner( |
| 116 gfx::Insets(resize_inside_bounds_size_, resize_inside_bounds_size_, | 127 gfx::Insets(resize_inside_bounds_size_, |
| 117 resize_inside_bounds_size_, resize_inside_bounds_size_)); | 128 resize_inside_bounds_size_, |
| 129 resize_inside_bounds_size_, |
| 130 resize_inside_bounds_size_)); |
| 118 #endif | 131 #endif |
| 119 } | 132 } |
| 120 | 133 |
| 121 // views::NonClientFrameView implementation. | 134 // views::NonClientFrameView implementation. |
| 122 | 135 |
| 123 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { | 136 gfx::Rect AppWindowFrameView::GetBoundsForClientView() const { |
| 124 if (window_->IsFrameless() || frame_->IsFullscreen()) | 137 if (window_->IsFrameless() || frame_->IsFullscreen()) |
| 125 return bounds(); | 138 return bounds(); |
| 126 return gfx::Rect(0, kCaptionHeight, width(), | 139 return gfx::Rect( |
| 127 std::max(0, height() - kCaptionHeight)); | 140 0, kCaptionHeight, width(), std::max(0, height() - kCaptionHeight)); |
| 128 } | 141 } |
| 129 | 142 |
| 130 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds( | 143 gfx::Rect AppWindowFrameView::GetWindowBoundsForClientBounds( |
| 131 const gfx::Rect& client_bounds) const { | 144 const gfx::Rect& client_bounds) const { |
| 132 if (window_->IsFrameless()) { | 145 if (window_->IsFrameless()) { |
| 133 gfx::Rect window_bounds = client_bounds; | 146 gfx::Rect window_bounds = client_bounds; |
| 134 // Enforce minimum size (1, 1) in case that client_bounds is passed with | 147 // Enforce minimum size (1, 1) in case that client_bounds is passed with |
| 135 // empty size. This could occur when the frameless window is being | 148 // empty size. This could occur when the frameless window is being |
| 136 // initialized. | 149 // initialized. |
| 137 if (window_bounds.IsEmpty()) { | 150 if (window_bounds.IsEmpty()) { |
| 138 window_bounds.set_width(1); | 151 window_bounds.set_width(1); |
| 139 window_bounds.set_height(1); | 152 window_bounds.set_height(1); |
| 140 } | 153 } |
| 141 return window_bounds; | 154 return window_bounds; |
| 142 } | 155 } |
| 143 | 156 |
| 144 int closeButtonOffsetX = | 157 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2; |
| 145 (kCaptionHeight - close_button_->height()) / 2; | |
| 146 int header_width = close_button_->width() + closeButtonOffsetX * 2; | 158 int header_width = close_button_->width() + closeButtonOffsetX * 2; |
| 147 return gfx::Rect(client_bounds.x(), | 159 return gfx::Rect(client_bounds.x(), |
| 148 std::max(0, client_bounds.y() - kCaptionHeight), | 160 std::max(0, client_bounds.y() - kCaptionHeight), |
| 149 std::max(header_width, client_bounds.width()), | 161 std::max(header_width, client_bounds.width()), |
| 150 client_bounds.height() + kCaptionHeight); | 162 client_bounds.height() + kCaptionHeight); |
| 151 } | 163 } |
| 152 | 164 |
| 153 int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) { | 165 int AppWindowFrameView::NonClientHitTest(const gfx::Point& point) { |
| 154 if (frame_->IsFullscreen()) | 166 if (frame_->IsFullscreen()) |
| 155 return HTCLIENT; | 167 return HTCLIENT; |
| 156 | 168 |
| 157 gfx::Rect expanded_bounds = bounds(); | 169 gfx::Rect expanded_bounds = bounds(); |
| 158 if (resize_outside_bounds_size_) | 170 if (resize_outside_bounds_size_) |
| 159 expanded_bounds.Inset(gfx::Insets(-resize_outside_bounds_size_, | 171 expanded_bounds.Inset(gfx::Insets(-resize_outside_bounds_size_, |
| 160 -resize_outside_bounds_size_, | 172 -resize_outside_bounds_size_, |
| 161 -resize_outside_bounds_size_, | 173 -resize_outside_bounds_size_, |
| 162 -resize_outside_bounds_size_)); | 174 -resize_outside_bounds_size_)); |
| 163 // Points outside the (possibly expanded) bounds can be discarded. | 175 // Points outside the (possibly expanded) bounds can be discarded. |
| 164 if (!expanded_bounds.Contains(point)) | 176 if (!expanded_bounds.Contains(point)) |
| 165 return HTNOWHERE; | 177 return HTNOWHERE; |
| 166 | 178 |
| 167 // Check the frame first, as we allow a small area overlapping the contents | 179 // Check the frame first, as we allow a small area overlapping the contents |
| 168 // to be used for resize handles. | 180 // to be used for resize handles. |
| 169 bool can_ever_resize = frame_->widget_delegate() ? | 181 bool can_ever_resize = frame_->widget_delegate() |
| 170 frame_->widget_delegate()->CanResize() : | 182 ? frame_->widget_delegate()->CanResize() |
| 171 false; | 183 : false; |
| 172 // Don't allow overlapping resize handles when the window is maximized or | 184 // Don't allow overlapping resize handles when the window is maximized or |
| 173 // fullscreen, as it can't be resized in those states. | 185 // fullscreen, as it can't be resized in those states. |
| 174 int resize_border = | 186 int resize_border = (frame_->IsMaximized() || frame_->IsFullscreen()) |
| 175 (frame_->IsMaximized() || frame_->IsFullscreen()) ? 0 : | 187 ? 0 |
| 176 resize_inside_bounds_size_; | 188 : resize_inside_bounds_size_; |
| 177 int frame_component = GetHTComponentForFrame(point, | 189 int frame_component = GetHTComponentForFrame(point, |
| 178 resize_border, | 190 resize_border, |
| 179 resize_border, | 191 resize_border, |
| 180 resize_area_corner_size_, | 192 resize_area_corner_size_, |
| 181 resize_area_corner_size_, | 193 resize_area_corner_size_, |
| 182 can_ever_resize); | 194 can_ever_resize); |
| 183 if (frame_component != HTNOWHERE) | 195 if (frame_component != HTNOWHERE) |
| 184 return frame_component; | 196 return frame_component; |
| 185 | 197 |
| 186 // Check for possible draggable region in the client area for the frameless | 198 // Check for possible draggable region in the client area for the frameless |
| (...skipping 21 matching lines...) Expand all Loading... |
| 208 } | 220 } |
| 209 if (minimize_button_ && minimize_button_->visible() && | 221 if (minimize_button_ && minimize_button_->visible() && |
| 210 minimize_button_->GetMirroredBounds().Contains(point)) { | 222 minimize_button_->GetMirroredBounds().Contains(point)) { |
| 211 return HTMINBUTTON; | 223 return HTMINBUTTON; |
| 212 } | 224 } |
| 213 | 225 |
| 214 // Caption is a safe default. | 226 // Caption is a safe default. |
| 215 return HTCAPTION; | 227 return HTCAPTION; |
| 216 } | 228 } |
| 217 | 229 |
| 218 void ShellWindowFrameView::GetWindowMask(const gfx::Size& size, | 230 void AppWindowFrameView::GetWindowMask(const gfx::Size& size, |
| 219 gfx::Path* window_mask) { | 231 gfx::Path* window_mask) { |
| 220 // We got nothing to say about no window mask. | 232 // We got nothing to say about no window mask. |
| 221 } | 233 } |
| 222 | 234 |
| 223 // views::View implementation. | 235 // views::View implementation. |
| 224 | 236 |
| 225 gfx::Size ShellWindowFrameView::GetPreferredSize() { | 237 gfx::Size AppWindowFrameView::GetPreferredSize() { |
| 226 gfx::Size pref = frame_->client_view()->GetPreferredSize(); | 238 gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
| 227 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | 239 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
| 228 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 240 return frame_->non_client_view() |
| 229 bounds).size(); | 241 ->GetWindowBoundsForClientBounds(bounds) |
| 242 .size(); |
| 230 } | 243 } |
| 231 | 244 |
| 232 void ShellWindowFrameView::Layout() { | 245 void AppWindowFrameView::Layout() { |
| 233 if (window_->IsFrameless()) | 246 if (window_->IsFrameless()) |
| 234 return; | 247 return; |
| 235 gfx::Size close_size = close_button_->GetPreferredSize(); | 248 gfx::Size close_size = close_button_->GetPreferredSize(); |
| 236 const int kButtonOffsetY = 0; | 249 const int kButtonOffsetY = 0; |
| 237 const int kButtonSpacing = 1; | 250 const int kButtonSpacing = 1; |
| 238 const int kRightMargin = 3; | 251 const int kRightMargin = 3; |
| 239 | 252 |
| 240 close_button_->SetBounds( | 253 close_button_->SetBounds(width() - kRightMargin - close_size.width(), |
| 241 width() - kRightMargin - close_size.width(), | 254 kButtonOffsetY, |
| 242 kButtonOffsetY, | 255 close_size.width(), |
| 243 close_size.width(), | 256 close_size.height()); |
| 244 close_size.height()); | |
| 245 | 257 |
| 246 bool can_ever_resize = frame_->widget_delegate() ? | 258 bool can_ever_resize = frame_->widget_delegate() |
| 247 frame_->widget_delegate()->CanResize() : | 259 ? frame_->widget_delegate()->CanResize() |
| 248 false; | 260 : false; |
| 249 maximize_button_->SetEnabled(can_ever_resize); | 261 maximize_button_->SetEnabled(can_ever_resize); |
| 250 gfx::Size maximize_size = maximize_button_->GetPreferredSize(); | 262 gfx::Size maximize_size = maximize_button_->GetPreferredSize(); |
| 251 maximize_button_->SetBounds( | 263 maximize_button_->SetBounds( |
| 252 close_button_->x() - kButtonSpacing - maximize_size.width(), | 264 close_button_->x() - kButtonSpacing - maximize_size.width(), |
| 253 kButtonOffsetY, | 265 kButtonOffsetY, |
| 254 maximize_size.width(), | 266 maximize_size.width(), |
| 255 maximize_size.height()); | 267 maximize_size.height()); |
| 256 gfx::Size restore_size = restore_button_->GetPreferredSize(); | 268 gfx::Size restore_size = restore_button_->GetPreferredSize(); |
| 257 restore_button_->SetBounds( | 269 restore_button_->SetBounds( |
| 258 close_button_->x() - kButtonSpacing - restore_size.width(), | 270 close_button_->x() - kButtonSpacing - restore_size.width(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 269 restore_button_->SetState(views::CustomButton::STATE_NORMAL); | 281 restore_button_->SetState(views::CustomButton::STATE_NORMAL); |
| 270 | 282 |
| 271 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); | 283 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); |
| 272 minimize_button_->SetBounds( | 284 minimize_button_->SetBounds( |
| 273 maximize_button_->x() - kButtonSpacing - minimize_size.width(), | 285 maximize_button_->x() - kButtonSpacing - minimize_size.width(), |
| 274 kButtonOffsetY, | 286 kButtonOffsetY, |
| 275 minimize_size.width(), | 287 minimize_size.width(), |
| 276 minimize_size.height()); | 288 minimize_size.height()); |
| 277 } | 289 } |
| 278 | 290 |
| 279 void ShellWindowFrameView::OnPaint(gfx::Canvas* canvas) { | 291 void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) { |
| 280 if (window_->IsFrameless()) | 292 if (window_->IsFrameless()) |
| 281 return; | 293 return; |
| 282 | 294 |
| 283 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 295 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 284 if (ShouldPaintAsActive()) { | 296 if (ShouldPaintAsActive()) { |
| 285 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 297 close_button_->SetImage( |
| 298 views::CustomButton::STATE_NORMAL, |
| 286 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 299 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
| 287 } else { | 300 } else { |
| 288 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 301 close_button_->SetImage( |
| 302 views::CustomButton::STATE_NORMAL, |
| 289 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); | 303 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); |
| 290 } | 304 } |
| 291 | 305 |
| 292 // TODO(jeremya): different look for inactive? | 306 // TODO(jeremya): different look for inactive? |
| 293 SkPaint paint; | 307 SkPaint paint; |
| 294 paint.setAntiAlias(false); | 308 paint.setAntiAlias(false); |
| 295 paint.setStyle(SkPaint::kFill_Style); | 309 paint.setStyle(SkPaint::kFill_Style); |
| 296 paint.setColor(SK_ColorWHITE); | 310 paint.setColor(SK_ColorWHITE); |
| 297 gfx::Path path; | 311 gfx::Path path; |
| 298 path.moveTo(0, 0); | 312 path.moveTo(0, 0); |
| 299 path.lineTo(width(), 0); | 313 path.lineTo(width(), 0); |
| 300 path.lineTo(width(), kCaptionHeight); | 314 path.lineTo(width(), kCaptionHeight); |
| 301 path.lineTo(0, kCaptionHeight); | 315 path.lineTo(0, kCaptionHeight); |
| 302 path.close(); | 316 path.close(); |
| 303 canvas->DrawPath(path, paint); | 317 canvas->DrawPath(path, paint); |
| 304 } | 318 } |
| 305 | 319 |
| 306 const char* ShellWindowFrameView::GetClassName() const { | 320 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; } |
| 307 return kViewClassName; | |
| 308 } | |
| 309 | 321 |
| 310 gfx::Size ShellWindowFrameView::GetMinimumSize() { | 322 gfx::Size AppWindowFrameView::GetMinimumSize() { |
| 311 gfx::Size min_size = frame_->client_view()->GetMinimumSize(); | 323 gfx::Size min_size = frame_->client_view()->GetMinimumSize(); |
| 312 if (window_->IsFrameless()) | 324 if (window_->IsFrameless()) |
| 313 return min_size; | 325 return min_size; |
| 314 | 326 |
| 315 // Ensure we can display the top of the caption area. | 327 // Ensure we can display the top of the caption area. |
| 316 gfx::Rect client_bounds = GetBoundsForClientView(); | 328 gfx::Rect client_bounds = GetBoundsForClientView(); |
| 317 min_size.Enlarge(0, client_bounds.y()); | 329 min_size.Enlarge(0, client_bounds.y()); |
| 318 // Ensure we have enough space for the window icon and buttons. We allow | 330 // Ensure we have enough space for the window icon and buttons. We allow |
| 319 // the title string to collapse to zero width. | 331 // the title string to collapse to zero width. |
| 320 int closeButtonOffsetX = | 332 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2; |
| 321 (kCaptionHeight - close_button_->height()) / 2; | |
| 322 int header_width = close_button_->width() + closeButtonOffsetX * 2; | 333 int header_width = close_button_->width() + closeButtonOffsetX * 2; |
| 323 if (header_width > min_size.width()) | 334 if (header_width > min_size.width()) |
| 324 min_size.set_width(header_width); | 335 min_size.set_width(header_width); |
| 325 return min_size; | 336 return min_size; |
| 326 } | 337 } |
| 327 | 338 |
| 328 gfx::Size ShellWindowFrameView::GetMaximumSize() { | 339 gfx::Size AppWindowFrameView::GetMaximumSize() { |
| 329 gfx::Size max_size = frame_->client_view()->GetMaximumSize(); | 340 gfx::Size max_size = frame_->client_view()->GetMaximumSize(); |
| 330 | 341 |
| 331 // Add to the client maximum size the height of any title bar and borders. | 342 // Add to the client maximum size the height of any title bar and borders. |
| 332 gfx::Size client_size = GetBoundsForClientView().size(); | 343 gfx::Size client_size = GetBoundsForClientView().size(); |
| 333 if (max_size.width()) | 344 if (max_size.width()) |
| 334 max_size.Enlarge(width() - client_size.width(), 0); | 345 max_size.Enlarge(width() - client_size.width(), 0); |
| 335 if (max_size.height()) | 346 if (max_size.height()) |
| 336 max_size.Enlarge(0, height() - client_size.height()); | 347 max_size.Enlarge(0, height() - client_size.height()); |
| 337 | 348 |
| 338 return max_size; | 349 return max_size; |
| 339 } | 350 } |
| 340 | 351 |
| 341 // views::ButtonListener implementation. | 352 // views::ButtonListener implementation. |
| 342 | 353 |
| 343 void ShellWindowFrameView::ButtonPressed(views::Button* sender, | 354 void AppWindowFrameView::ButtonPressed(views::Button* sender, |
| 344 const ui::Event& event) { | 355 const ui::Event& event) { |
| 345 DCHECK(!window_->IsFrameless()); | 356 DCHECK(!window_->IsFrameless()); |
| 346 if (sender == close_button_) | 357 if (sender == close_button_) |
| 347 frame_->Close(); | 358 frame_->Close(); |
| 348 else if (sender == maximize_button_) | 359 else if (sender == maximize_button_) |
| 349 frame_->Maximize(); | 360 frame_->Maximize(); |
| 350 else if (sender == restore_button_) | 361 else if (sender == restore_button_) |
| 351 frame_->Restore(); | 362 frame_->Restore(); |
| 352 else if (sender == minimize_button_) | 363 else if (sender == minimize_button_) |
| 353 frame_->Minimize(); | 364 frame_->Minimize(); |
| 354 } | 365 } |
| 355 | 366 |
| 356 } // namespace apps | 367 } // namespace apps |
| OLD | NEW |