Chromium Code Reviews| Index: chrome/browser/ui/views/frame/browser_frame_win.cc |
| =================================================================== |
| --- chrome/browser/ui/views/frame/browser_frame_win.cc (revision 143310) |
| +++ chrome/browser/ui/views/frame/browser_frame_win.cc (working copy) |
| @@ -6,7 +6,6 @@ |
| #include <dwmapi.h> |
| #include <shellapi.h> |
| - |
| #include <set> |
| #include "base/command_line.h" |
| @@ -31,6 +30,7 @@ |
| #include "googleurl/src/gurl.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/models/simple_menu_model.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/theme_provider.h" |
| @@ -95,7 +95,8 @@ |
| browser_view_(browser_view), |
| browser_frame_(browser_frame), |
| system_menu_delegate_(new SystemMenuModelDelegate(browser_view, |
| - browser_view->browser())) { |
| + browser_view->browser())), |
| + cached_minimize_button_x_delta_(0) { |
| if (base::win::IsMetroProcess()) { |
| browser_view->SetWindowSwitcherButton( |
| MakeWindowSwitcherButton(this, browser_view->IsOffTheRecord())); |
| @@ -250,6 +251,12 @@ |
| views::NativeWidgetWin::Close(); |
| } |
| +void BrowserFrameWin::OnActivate(UINT action, BOOL minimized, HWND window) { |
| + if (action != WA_INACTIVE) |
| + CacheMinimizeButtonDelta(); |
| + views::NativeWidgetWin::OnActivate(action, minimized, window); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // BrowserFrameWin, NativeBrowserFrame implementation: |
| @@ -275,15 +282,28 @@ |
| } |
| int BrowserFrameWin::GetMinimizeButtonOffset() const { |
| - TITLEBARINFOEX titlebar_info; |
| + // The WM_GETTITLEBARINFOEX message can fail if we are not active/visible. |
| + TITLEBARINFOEX titlebar_info = {0}; |
| titlebar_info.cbSize = sizeof(TITLEBARINFOEX); |
| - SendMessage(GetNativeView(), WM_GETTITLEBARINFOEX, 0, (WPARAM)&titlebar_info); |
| + BOOL ret = SendMessage(GetNativeView(), WM_GETTITLEBARINFOEX, 0, |
|
sky
2012/06/21 18:13:40
Remove 'ret' since as you said its always true ad
ananta
2012/06/21 18:27:46
Done.
|
| + reinterpret_cast<WPARAM>(&titlebar_info)); |
| CPoint minimize_button_corner(titlebar_info.rgrect[2].left, |
| titlebar_info.rgrect[2].top); |
| MapWindowPoints(HWND_DESKTOP, GetNativeView(), &minimize_button_corner, 1); |
| - return minimize_button_corner.x; |
| + if (minimize_button_corner.x) |
| + return minimize_button_corner.x; |
| + |
| + DCHECK(cached_minimize_button_x_delta_); |
| + |
| + RECT client_rect = {0}; |
| + GetClientRect(&client_rect); |
| + |
| + if (base::i18n::IsRTL()) |
| + return cached_minimize_button_x_delta_; |
| + else |
| + return client_rect.right - cached_minimize_button_x_delta_; |
| } |
| void BrowserFrameWin::TabStripDisplayModeChanged() { |
| @@ -505,7 +525,24 @@ |
| UTF8ToWide(current_tab->GetURL().spec())); |
| } |
| +void BrowserFrameWin::CacheMinimizeButtonDelta() { |
| + int minimize_offset = GetMinimizeButtonOffset(); |
|
sky
2012/06/21 18:13:40
The way you have the code now you're only going to
ananta
2012/06/21 18:27:46
Thanks for catching this. Isolated the WM_GETTITLE
|
| + if (!minimize_offset) |
| + return; |
| + RECT rect = {0}; |
| + GetClientRect(&rect); |
| + // Calculate and cache the value of the minimize button delta, i.e. the |
| + // offset to be applied to the left or right edge of the client rect |
| + // depending on whether the language is RTL or not. |
| + // This cached value is only used if the WM_GETTITLEBARINFOEX message fails |
| + // to get the offset of the minimize button. |
| + if (base::i18n::IsRTL()) |
| + cached_minimize_button_x_delta_ = minimize_offset; |
| + else |
| + cached_minimize_button_x_delta_ = rect.right - minimize_offset; |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // BrowserFrame, public: |