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

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

Issue 21116: Support custom border widths. Allow user to resize the window (instead of do... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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
« no previous file with comments | « chrome/browser/views/frame/aero_glass_frame.cc ('k') | chrome/views/non_client_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/frame/aero_glass_non_client_view.h" 5 #include "chrome/browser/views/frame/aero_glass_non_client_view.h"
6 6
7 #include "chrome/app/theme/theme_resources.h" 7 #include "chrome/app/theme/theme_resources.h"
8 #include "chrome/browser/views/frame/browser_view.h" 8 #include "chrome/browser/views/frame/browser_view.h"
9 #include "chrome/browser/views/tabs/tab_strip.h" 9 #include "chrome/browser/views/tabs/tab_strip.h"
10 #include "chrome/common/gfx/chrome_canvas.h" 10 #include "chrome/common/gfx/chrome_canvas.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // static 83 // static
84 SkBitmap* AeroGlassWindowResources::standard_frame_bitmaps_[]; 84 SkBitmap* AeroGlassWindowResources::standard_frame_bitmaps_[];
85 SkBitmap AeroGlassWindowResources::app_top_left_; 85 SkBitmap AeroGlassWindowResources::app_top_left_;
86 SkBitmap AeroGlassWindowResources::app_top_center_; 86 SkBitmap AeroGlassWindowResources::app_top_center_;
87 SkBitmap AeroGlassWindowResources::app_top_right_; 87 SkBitmap AeroGlassWindowResources::app_top_right_;
88 88
89 AeroGlassWindowResources* AeroGlassNonClientView::resources_ = NULL; 89 AeroGlassWindowResources* AeroGlassNonClientView::resources_ = NULL;
90 SkBitmap AeroGlassNonClientView::distributor_logo_; 90 SkBitmap AeroGlassNonClientView::distributor_logo_;
91 91
92 // The distance between the top of the TabStrip and the top of the non-client
93 // area of the window.
94 static const int kNoTitleTopSpacing = 8;
95 // The width of the client edge to the left and right of the window. 92 // The width of the client edge to the left and right of the window.
96 static const int kWindowHorizontalClientEdgeWidth = 3; 93 static const int kClientEdgeWidth = 3;
97 // The height of the client edge to the bottom of the window. 94 // The height of the client edge to the bottom of the window.
98 static const int kWindowBottomClientEdgeHeight = 2; 95 static const int kClientEdgeHeight = 2;
96 // In the window corners, the resize areas don't actually expand bigger, but the
97 // 16 px at the end of the top and bottom edges triggers diagonal resizing.
98 const int kResizeEdgeWidth = 16;
99 // The horizontal distance between the left of the minimize button and the 99 // The horizontal distance between the left of the minimize button and the
100 // right edge of the distributor logo. 100 // right edge of the distributor logo.
101 static const int kDistributorLogoHorizontalOffset = 7; 101 static const int kDistributorLogoHorizontalOffset = 7;
102 // The distance from the top of the non-client view and the top edge of the 102 // The distance from the top of the non-client view and the top edge of the
103 // distributor logo. 103 // distributor logo.
104 static const int kDistributorLogoVerticalOffset = 3; 104 static const int kDistributorLogoVerticalOffset = 3;
105 // The distance of the TabStrip from the top of the window's client area. 105 // The distance of the TabStrip from the top of the window's client area.
106 static const int kTabStripY = 19; 106 static const int kTabStripY = 19;
107 // How much space on the right is not used for the tab strip (to provide 107 // How much space on the right is not used for the tab strip (to provide
108 // separation between the tabs and the window controls). 108 // separation between the tabs and the window controls).
109 static const int kTabStripRightHorizOffset = 30; 109 static const int kTabStripRightHorizOffset = 30;
110 // A single pixel. 110 // A single pixel.
111 static const int kPixel = 1; 111 static const int kPixel = 1;
112 // The height of the sizing border.
113 static const int kWindowSizingBorderSize = 8;
114 // The size (width/height) of the window icon. 112 // The size (width/height) of the window icon.
115 static const int kWindowIconSize = 16; 113 static const int kWindowIconSize = 16;
116 // In maximized mode, the OTR avatar starts 2 px below the top of the screen, so 114 // In maximized mode, the OTR avatar starts 2 px below the top of the screen, so
117 // that it doesn't extend into the "3D edge" portion of the titlebar. 115 // that it doesn't extend into the "3D edge" portion of the titlebar.
118 const int kOTRMaximizedTopSpacing = 2; 116 const int kOTRMaximizedTopSpacing = 2;
119 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the 117 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the
120 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the 118 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
121 // user). 119 // user).
122 const int kOTRBottomSpacing = 2; 120 const int kOTRBottomSpacing = 2;
123 // There are 2 px on each side of the OTR avatar (between the frame border and 121 // There are 2 px on each side of the OTR avatar (between the frame border and
124 // it on the left, and between it and the tabstrip on the right). 122 // it on the left, and between it and the tabstrip on the right).
125 const int kOTRSideSpacing = 2; 123 const int kOTRSideSpacing = 2;
126 124
127 /////////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////////
128 // AeroGlassNonClientView, public: 126 // AeroGlassNonClientView, public:
129 127
130 AeroGlassNonClientView::AeroGlassNonClientView(AeroGlassFrame* frame, 128 AeroGlassNonClientView::AeroGlassNonClientView(AeroGlassFrame* frame,
131 BrowserView* browser_view) 129 BrowserView* browser_view)
132 : frame_(frame), 130 : frame_(frame),
133 browser_view_(browser_view) { 131 browser_view_(browser_view) {
134 InitClass(); 132 InitClass();
135 } 133 }
136 134
137 AeroGlassNonClientView::~AeroGlassNonClientView() { 135 AeroGlassNonClientView::~AeroGlassNonClientView() {
138 } 136 }
139 137
140 gfx::Rect AeroGlassNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) { 138 gfx::Rect AeroGlassNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) {
141 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? 139 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ?
142 (otr_avatar_bounds_.right() + kOTRSideSpacing) : 140 (otr_avatar_bounds_.right() + kOTRSideSpacing) : kClientEdgeWidth;
143 kWindowHorizontalClientEdgeWidth;
144 int tabstrip_width = width() - tabstrip_x - kTabStripRightHorizOffset - 141 int tabstrip_width = width() - tabstrip_x - kTabStripRightHorizOffset -
145 (frame_->IsMaximized() ? frame_->GetMinimizeButtonOffset() : 0); 142 (frame_->IsMaximized() ? frame_->GetMinimizeButtonOffset() : 0);
146 int tabstrip_y = 143 int tabstrip_y =
147 frame_->IsMaximized() ? (CalculateNonClientTopHeight() - 2) : kTabStripY; 144 frame_->IsMaximized() ? (CalculateNonClientTopHeight() - 2) : kTabStripY;
148 return gfx::Rect(tabstrip_x, tabstrip_y, std::max(0, tabstrip_width), 145 return gfx::Rect(tabstrip_x, tabstrip_y, std::max(0, tabstrip_width),
149 tabstrip->GetPreferredHeight()); 146 tabstrip->GetPreferredHeight());
150 } 147 }
151 148
152 /////////////////////////////////////////////////////////////////////////////// 149 ///////////////////////////////////////////////////////////////////////////////
153 // AeroGlassNonClientView, views::NonClientView implementation: 150 // AeroGlassNonClientView, views::NonClientView implementation:
154 151
155 gfx::Rect AeroGlassNonClientView::CalculateClientAreaBounds(int win_width, 152 gfx::Rect AeroGlassNonClientView::CalculateClientAreaBounds(int win_width,
156 int win_height) cons t { 153 int win_height) cons t {
157 if (!browser_view_->IsTabStripVisible()) 154 if (!browser_view_->IsTabStripVisible())
158 return gfx::Rect(0, 0, width(), height()); 155 return gfx::Rect(0, 0, width(), height());
159 156
160 int top_margin = CalculateNonClientTopHeight(); 157 int top_margin = CalculateNonClientTopHeight();
161 return gfx::Rect(kWindowHorizontalClientEdgeWidth, top_margin, 158 return gfx::Rect(kClientEdgeWidth, top_margin,
162 std::max(0, win_width - (2 * kWindowHorizontalClientEdgeWidth)), 159 std::max(0, win_width - (2 * kClientEdgeWidth)),
163 std::max(0, win_height - top_margin - kWindowBottomClientEdgeHeight)); 160 std::max(0, win_height - top_margin - kClientEdgeHeight));
164 } 161 }
165 162
166 gfx::Size AeroGlassNonClientView::CalculateWindowSizeForClientSize( 163 gfx::Size AeroGlassNonClientView::CalculateWindowSizeForClientSize(
167 int width, 164 int width,
168 int height) const { 165 int height) const {
169 int top_margin = CalculateNonClientTopHeight(); 166 int top_margin = CalculateNonClientTopHeight();
170 return gfx::Size(width + (2 * kWindowHorizontalClientEdgeWidth), 167 return gfx::Size(width + (2 * kClientEdgeWidth),
171 height + top_margin + kWindowBottomClientEdgeHeight); 168 height + top_margin + kClientEdgeHeight);
172 } 169 }
173 170
174 CPoint AeroGlassNonClientView::GetSystemMenuPoint() const { 171 CPoint AeroGlassNonClientView::GetSystemMenuPoint() const {
175 CPoint offset(0, 0); 172 CPoint offset(0, 0);
176 MapWindowPoints(GetWidget()->GetHWND(), HWND_DESKTOP, &offset, 1); 173 MapWindowPoints(GetWidget()->GetHWND(), HWND_DESKTOP, &offset, 1);
177 return offset; 174 return offset;
178 } 175 }
179 176
180 int AeroGlassNonClientView::NonClientHitTest(const gfx::Point& point) { 177 int AeroGlassNonClientView::NonClientHitTest(const gfx::Point& point) {
181 CRect bounds; 178 // If we don't have a tabstrip, we haven't customized the frame, so Windows
182 CPoint test_point = point.ToPOINT(); 179 // can figure this out. If the point isn't within our bounds, then it's in
180 // the native portion of the frame, so again Windows can figure it out.
181 if (!browser_view_->IsTabStripVisible() || !bounds().Contains(point))
182 return HTNOWHERE;
183 183
184 // See if the client view intersects the non-client area (e.g. blank areas 184 // See if the client view intersects the non-client area (e.g. blank areas
185 // of the TabStrip). 185 // of the TabStrip).
186 int component = frame_->client_view()->NonClientHitTest(point); 186 int frame_component = frame_->client_view()->NonClientHitTest(point);
187 if (component != HTNOWHERE) 187 if (frame_component != HTNOWHERE)
188 return component; 188 return frame_component;
189 189
190 // This check is only done when we have a tabstrip, which is the only time 190 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
191 // that we have a non-standard non-client area. 191 int resize_width = kResizeEdgeWidth - border_thickness;
192 if (browser_view_->IsTabStripVisible()) { 192 if (point.x() < kClientEdgeWidth) {
193 // Because we tell Windows that our client area extends all the way to the 193 if (point.y() < border_thickness)
194 // top of the browser window, but our BrowserView doesn't actually go up tha t 194 return HTTOPLEFT;
195 // high, we need to make sure the right hit-test codes are returned for the 195 if (point.y() >= (height() - kClientEdgeHeight))
196 // caption area above the tabs and the top sizing border. 196 return HTBOTTOMLEFT;
197 int client_view_right = 197 return HTLEFT;
198 frame_->client_view()->x() + frame_->client_view()->width();
199 if (point.x() >= frame_->client_view()->x() &&
200 point.x() < client_view_right) {
201 if (point.y() < kWindowSizingBorderSize)
202 return HTTOP;
203 if (point.y() < (y() + height()))
204 return HTCAPTION;
205 }
206 } 198 }
207 199 if (point.x() >= (width() - kClientEdgeWidth)) {
208 // Let Windows figure it out. 200 if (point.y() < border_thickness)
209 return HTNOWHERE; 201 return HTTOPRIGHT;
202 if (point.y() >= (height() - kClientEdgeHeight))
203 return HTBOTTOMRIGHT;
204 return HTRIGHT;
205 }
206 if (point.y() < border_thickness) {
207 if (point.x() < resize_width)
208 return HTTOPLEFT;
209 if (point.x() >= (width() - resize_width))
210 return HTTOPRIGHT;
211 return HTTOP;
212 }
213 if (point.y() >= (height() - kClientEdgeHeight)) {
214 if (point.x() < resize_width)
215 return HTBOTTOMLEFT;
216 if (point.x() >= (width() - resize_width))
217 return HTBOTTOMRIGHT;
218 return HTBOTTOM;
219 }
220 return HTCAPTION;
210 } 221 }
211 222
212 void AeroGlassNonClientView::GetWindowMask(const gfx::Size& size, 223 void AeroGlassNonClientView::GetWindowMask(const gfx::Size& size,
213 gfx::Path* window_mask) { 224 gfx::Path* window_mask) {
214 // We use the native window region. 225 // We use the native window region.
215 } 226 }
216 227
217 void AeroGlassNonClientView::EnableClose(bool enable) { 228 void AeroGlassNonClientView::EnableClose(bool enable) {
218 // This is handled exclusively by Window. 229 // This is handled exclusively by Window.
219 } 230 }
(...skipping 15 matching lines...) Expand all
235 } 246 }
236 247
237 void AeroGlassNonClientView::Layout() { 248 void AeroGlassNonClientView::Layout() {
238 LayoutOTRAvatar(); 249 LayoutOTRAvatar();
239 LayoutDistributorLogo(); 250 LayoutDistributorLogo();
240 LayoutClientView(); 251 LayoutClientView();
241 } 252 }
242 253
243 gfx::Size AeroGlassNonClientView::GetPreferredSize() { 254 gfx::Size AeroGlassNonClientView::GetPreferredSize() {
244 gfx::Size prefsize = frame_->client_view()->GetPreferredSize(); 255 gfx::Size prefsize = frame_->client_view()->GetPreferredSize();
245 prefsize.Enlarge(2 * kWindowHorizontalClientEdgeWidth, 256 prefsize.Enlarge(2 * kClientEdgeWidth,
246 CalculateNonClientTopHeight() + 257 CalculateNonClientTopHeight() + kClientEdgeHeight);
247 kWindowBottomClientEdgeHeight);
248 return prefsize; 258 return prefsize;
249 } 259 }
250 260
251 void AeroGlassNonClientView::ViewHierarchyChanged(bool is_add, 261 void AeroGlassNonClientView::ViewHierarchyChanged(bool is_add,
252 views::View* parent, 262 views::View* parent,
253 views::View* child) { 263 views::View* child) {
254 if (is_add && child == this) { 264 if (is_add && child == this) {
255 DCHECK(GetWidget()); 265 DCHECK(GetWidget());
256 DCHECK(frame_->client_view()->GetParent() != this); 266 DCHECK(frame_->client_view()->GetParent() != this);
257 AddChildView(frame_->client_view()); 267 AddChildView(frame_->client_view());
258 } 268 }
259 } 269 }
260 270
261 /////////////////////////////////////////////////////////////////////////////// 271 ///////////////////////////////////////////////////////////////////////////////
262 // AeroGlassNonClientView, private: 272 // AeroGlassNonClientView, private:
263 273
264 int AeroGlassNonClientView::CalculateNonClientTopHeight() const { 274 int AeroGlassNonClientView::CalculateNonClientTopHeight() const {
265 if (frame_->window_delegate()->ShouldShowWindowTitle()) 275 return browser_view_->IsTabStripVisible() ?
266 return browser_view_->IsToolbarVisible() ? -1 : 0; 276 GetSystemMetrics(SM_CYSIZEFRAME) : 0;
267 return kNoTitleTopSpacing;
268 } 277 }
269 278
270 void AeroGlassNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) { 279 void AeroGlassNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) {
271 if (!browser_view_->ShouldShowOffTheRecordAvatar()) 280 if (!browser_view_->ShouldShowOffTheRecordAvatar())
272 return; 281 return;
273 282
274 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 283 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
275 canvas->DrawBitmapInt(otr_avatar_icon, 0, 284 canvas->DrawBitmapInt(otr_avatar_icon, 0,
276 (otr_avatar_icon.height() - otr_avatar_bounds_.height()) / 2, 285 (otr_avatar_icon.height() - otr_avatar_bounds_.height()) / 2,
277 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), 286 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 375 }
367 376
368 void AeroGlassNonClientView::LayoutOTRAvatar() { 377 void AeroGlassNonClientView::LayoutOTRAvatar() {
369 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 378 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
370 int top_height = (frame_->IsMaximized() ? 379 int top_height = (frame_->IsMaximized() ?
371 (CalculateNonClientTopHeight() - 2) : kTabStripY); 380 (CalculateNonClientTopHeight() - 2) : kTabStripY);
372 int tabstrip_height = browser_view_->GetTabStripHeight() - kOTRBottomSpacing; 381 int tabstrip_height = browser_view_->GetTabStripHeight() - kOTRBottomSpacing;
373 int otr_height = frame_->IsMaximized() ? 382 int otr_height = frame_->IsMaximized() ?
374 (tabstrip_height - kOTRMaximizedTopSpacing) : 383 (tabstrip_height - kOTRMaximizedTopSpacing) :
375 otr_avatar_icon.height(); 384 otr_avatar_icon.height();
376 otr_avatar_bounds_.SetRect( 385 otr_avatar_bounds_.SetRect(kClientEdgeWidth + kOTRSideSpacing,
377 kWindowHorizontalClientEdgeWidth + kOTRSideSpacing,
378 top_height + tabstrip_height - otr_height, otr_avatar_icon.width(), 386 top_height + tabstrip_height - otr_height, otr_avatar_icon.width(),
379 otr_height); 387 otr_height);
380 } 388 }
381 389
382 void AeroGlassNonClientView::LayoutDistributorLogo() { 390 void AeroGlassNonClientView::LayoutDistributorLogo() {
383 if (distributor_logo_.empty()) 391 if (distributor_logo_.empty())
384 return; 392 return;
385 393
386 int logo_w = distributor_logo_.width(); 394 int logo_w = distributor_logo_.width();
387 int logo_h = distributor_logo_.height(); 395 int logo_h = distributor_logo_.height();
(...skipping 18 matching lines...) Expand all
406 resources_ = new AeroGlassWindowResources; 414 resources_ = new AeroGlassWindowResources;
407 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 415 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
408 #if defined(GOOGLE_CHROME_BUILD) 416 #if defined(GOOGLE_CHROME_BUILD)
409 distributor_logo_ = *rb.GetBitmapNamed(IDR_DISTRIBUTOR_LOGO); 417 distributor_logo_ = *rb.GetBitmapNamed(IDR_DISTRIBUTOR_LOGO);
410 #endif 418 #endif
411 419
412 initialized = true; 420 initialized = true;
413 } 421 }
414 } 422 }
415 423
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/aero_glass_frame.cc ('k') | chrome/views/non_client_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698